deno
deno copied to clipboard
import.meta.resolve with npm packages
Related: https://github.com/denoland/deno/issues/16089
Every time I try to resolve a npm package:
const preact_specifier = import.meta.resolve("npm:preact");
I get the error:
Uncaught TypeError: "npm:" specifiers are currently not supported in import.meta.resolve()
I would rather the old behavior, returning simply npm:preact
. This error is very unfortunated because now it's not possible to get the final specifier if the specifier is mapped in the import map:
{
"imports": {
"npm:preact": "https://esm.sh/preact"
}
}
I guess this is the intended behavior would like to know the explanation for that decision.
Strictly speaking, the specifier being loaded in the module registry is npm:preact
in this case (and so far as it only has one representation in a given Deno application lifetime). So that this does sound like the sensible behaviour to me, while still treating the real cache location etc as an internal implementation detail.
To clarify, the sensible behavior to me is:
import.meta.resolve("npm:preact"); // Returns "npm:preact"
With this import map:
{
"imports": {
"npm:preact": "https://esm.sh/preact"
}
}
import.meta.resolve("npm:preact"); // Returns "https://esm.sh/preact"
I agree.
Opened https://github.com/denoland/deno_core/pull/354 that will make it easier to customize.