Closed jimisaacs closed 1 year ago
Hey just dug into this, it's happening because one file https://deno.land/x/fresh@1.0.2/src/runtime/main.ts
is used by esbuild here but never imported directly so it's never downloaded as a vendor dependency.
Including it in your vendor deps fixes the issue.
deno vendor main.ts dev.ts https://deno.land/x/fresh@1.0.2/src/runtime/main.ts
Note: Your
deno.json
inport_map needs to be reset to the original map to NOT use vendor for you to "re-vendor"
As a possible side issue here the vendor map here should be prioritizing the map used in deno.json
over the map in the root directory. Right now my fresh instance created with deno task start
and vendored
fresh is still using the default map internally for esbuild.
Using deno 1.25.4 and fresh 1.1.1, vendoring is failing with the below
$ deno vendor ./main.ts
error: Expected ';', '}' or <eof> at file:///C:/deno-fresh-demo/deno.json:2:10
It seems linked to fact that deno vendor is failing when encountering a type assertion (The fresh manifest is importing deno.json). see tracking issue https://github.com/denoland/deno/issues/15634
The fix for the parsing issue mentioned above is now released on latest deno canary, However there are still a couple more issues with the generated vendor import_maps
$ deno run -A ./main.ts
error: Relative import path "preact/jsx-runtime" not prefixed with / or ./ or ../ and not in import map from "file:///C:/islands/Counter.tsx"
tracking issue: https://github.com/denoland/deno/issues/16108
If the vendor import map is manually adjusted with "preact/jsx-runtime": "https://esm.sh/preact@10.11.0/jsx-runtime"
to pass this error, then the twind plugin seems to also be an issue, as below
deno:data:application/javascript,import hydrate from "file:///C:/deno-fresh-demo/vendor/deno.land/x/fresh@1.1.1/plugins/twind/main.ts";import options from "file:///C:/deno-fresh-demo/twind.config.ts";export default function(state) { hydrate(options, state); }:1:20:
1 │ import hydrate from "file:///C:/deno-fresh-demo/vendor/deno.land/x/fresh@1.1.1/plugins/twind/main.ts";import options from "file:///C:/...
╵ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
An error occurred during route handling or page rendering. Error: Build failed with 2 errors:
error: The module was missing and could not be loaded.
@sylc I managed to get exactly to this point, and go beyond by adding the missing deps to the vendor command:
deno vendor --import-map=import_map.json dev.ts main.ts https://deno.land/x/fresh@1.1.2/src/runtime/main_dev.ts https://deno.land/x/fresh@1.1.2/plugins/twind/main.ts
I'd really love to have a fix for "preact/jsx-runtime"
not having to be manually added, however.
The current workaround (deno 1.35.0, fresh 1.2.0):
> deno vendor main.ts https://deno.land/x/fresh@1.2.0/plugins/twind/main.ts https://esm.sh/preact@10.15.1/jsx-runtime https://deno.land/x/fresh@1.2.0/src/runtime/entrypoints/deserializer.ts https://deno.land/x/fresh@1.2.0/src/runtime/entrypoints/main_dev.ts https://deno.land/x/fresh@1.2.0/src/runtime/entrypoints/signals.ts
Vendored 213 modules into vendor/ directory.
Updated your local Deno configuration file with a reference to the new vendored import map at vendor/import_map.json. Invoking Deno subcommands will now automatically resolve using the vendored modules. You may override this by providing the `--import-map <other-import-map>` flag or by manually editing your Deno configuration file.
then add
"preact/jsx-runtime": "./esm.sh/preact@10.15.1/jsx-runtime.js"
to vendor/import_map.json
then work ok:
> deno run -A --no-remote main.ts
🍋 Fresh ready
Local: http://localhost:8000/
@secext2022 FYI: The missing JSX import source package in the import map was fixed in the newest Deno 1.35.1 release. This is the PR that fixed it https://github.com/denoland/deno/pull/19724
ok, now test with deno 1.35.1
> deno --version
deno 1.35.1 (release, x86_64-unknown-linux-gnu)
v8 11.6.189.7
typescript 5.1.6
> deno vendor main.ts https://deno.land/x/fresh@1.2.0/plugins/twind/main.ts https://deno.land/x/fresh@1.2.0/src/runtime/entrypoints/deserializer.ts https://deno.land/x/fresh@1.2.0/src/runtime/entrypoints/main_dev.ts https://deno.land/x/fresh@1.2.0/src/runtime/entrypoints/signals.ts
Vendored 213 modules into vendor/ directory.
Updated your local Deno configuration file with a reference to the new vendored import map at vendor/import_map.json. Invoking Deno subcommands will now automatically resolve using the vendored modules. You may override this by providing the `--import-map <other-import-map>` flag or by manually editing your Deno configuration file.
> deno run -A --no-remote main.ts
🍋 Fresh ready
Local: http://localhost:8000/
nice !
Closing because vendoring works with Fresh now. We're in the process of improving the vendor
command in Deno in general, but that's not specific to Fresh.
Are we sure this is working? In a clean project I tried to do the following:
deno vendor main.ts
deno run -A --no-remote main.ts
and got the following:
Warning "importMap" setting is ignored when "imports" or "scopes" are specified in the config file.
error: A remote specifier was requested: "https://deno.land/std@0.193.0/dotenv/load.ts", but --no-remote is specified.
at file:///Users/reed/code/temp/vendor_test/main.ts:7:8
I started testing this because I think https://github.com/denoland/fresh/pull/1008 can be closed. Obviously my test didn't go so well, but regardless, the PR seems to encourage a workaround approach, as opposed to getting the core problem fixed.
@deer
After deno vendor
, you have to remove "imports"
section from deno.json
file.
And you should also vendor more files, not only main.ts
(see comment above)
Thanks @secext2022 , that sorted out the remote specifier
error. I will create some documentation about vendoring a Fresh project using this information.
@marvinhagemeister, what do you think about closing https://github.com/denoland/fresh/pull/1008 then? It seems like everything is working now.
@deer Vendoring is about to change soon to make it less confusing. @dsherret has been doing fantastic work in that direction.
Regarding #1008 : I totally get where they are coming from, but the solution proposed seems more like a hack and potentially confusing for newcomers as to why there are floating dynamic imports. I'd rather make such workaround unnecessarily entirely.
This worked for me when trying to vendor only fresh:
Remove $fresh/
from "imports"
in deno.json
Run:
deno vendor https://deno.land/x/fresh@1.3.1/ https://deno.land/x/fresh@1.3.1/dev.ts https://deno.land/x/fresh@1.3.1/runtime.ts https://deno.land/x/fresh@1.3.1/server.ts
Remove the added "importMap": "./vendor/import_map.json"
from deno.json
Add the following to "imports"
in deno.json
:
"$fresh/": "./vendor/deno.land/x/fresh@1.3.1/",
"$fresh/dev.ts": "./vendor/deno.land/x/fresh@1.3.1/dev.ts",
"$fresh/server.ts": "./vendor/deno.land/x/fresh@1.3.1/server.ts",
"$fresh/runtime.ts": "./vendor/deno.land/x/fresh@1.3.1/runtime.ts",
Not sure, but this doesn't look good?