esm.sh icon indicating copy to clipboard operation
esm.sh copied to clipboard

esm is building modules with importing `node:preact` instead of `npm:preact`

Open renhiyama opened this issue 1 year ago • 5 comments

For reference, node:<pkg> is only allowed to load native node modules and not third party modules. However, https://esm.sh/*[email protected]?target=node&bundle -> https://esm.sh/v111/[email protected]/X-ZS8q/node/preact-render-to-string.bundle.js has imports as node:preact. Same is happening with other packages like when using *swr (notice that * for external deps) and it targets node:react. I hope esm.sh can fix this "bug" :) As far as I can remember deno should fail to import these too as deno itself also uses npm prefix to import packages from npm.

renhiyama avatar Mar 09 '23 17:03 renhiyama

in deno, you need to add "preact" to your import maps for the *preact-render-to-string pattern:

{
  "imports": {
    "preact-render-to-string": "https://esm.sh/*[email protected]",
    "preact": "https://esm.sh/preact"
  }
}

i saw you are using the "node" target, where the "node:preact" come from?

ije avatar Mar 21 '23 15:03 ije

I'm working on an experimental URL imports feature that downloads the files just like deno does and then imports them. So if I'm not wrong, deno adds node:<pkg name> to their module name resolution if there's <pkg name> in import map? Let me know if this is the intended way so I can make changes to act the same way.

renhiyama avatar Mar 22 '23 17:03 renhiyama

But as far as I'm aware, you shouldn't be using node:<pkg name> as they're reserved for native node modules and not third party npm packages 😅 If possible, please use npm:<pkg name> instead of node:<pkg name> for better consistency.

renhiyama avatar Mar 22 '23 17:03 renhiyama

so can I close this? thanks

ije avatar Mar 23 '23 08:03 ije

Did u fix it? If yes, then you can close it

renhiyama avatar Mar 24 '23 03:03 renhiyama