Doesn't work with `npm:` specifiers
Closed this issue · 3 comments
✘ [ERROR] [plugin deno] Failed to call 'deno info' on 'file:///.../.../index.js'
This could potentially be solved with an unstable
flag. I will open a PR when my last one is merged. Please take a look.
Is there any work being done on this at the moment?
@codesculpture, @itsdouges and I are looking into this problem
I made a plugin to rewrite npm:...
to esm.sh
before deno plugin like this:
await esbuild.build({
plugins: [
// ESBuild plugin to rewrite import starting "npm:" to "esm.sh" for https plugin
{
name: "the-npm-plugin",
setup(build: any) {
build.onResolve({ filter: /^npm:/ }, (args: any) => {
return {
path: args.path.replace(/^npm:/, "//esm.sh/"),
namespace: "https",
};
});
},
},
denoPlugin() as any,
],
However it doesn't utilize the cache, it seems to be downloading all of the files I rewrite like that on each build.
Also it seems to be that tree shaking doesn't work for those imports (currently I use it to just date-fns) which is a bummer.
But it works for the time being.
Edit I also noticed I can get it to work like this:
import_map.json
{
"imports": {
"npm:date-fns": "https://esm.sh/date-fns"
}
}
denoPlugin({
importMapURL: new URL("./import_map.json", import.meta.url),
}) as any,
Problem with this approach is the same as with my plugin above, the esbuild command re-downloads the URLs each time. In my example it re-downloads https://esm.sh/date-fns
on each build and it makes it slow.