jspm / project

Roadmap and management repo for the jspm project
161 stars 8 forks source link

'preact/hooks' does not provide an export named 'default' #100

Closed sibbng closed 3 years ago

sibbng commented 3 years ago

Hi, I'm trying to convert my Skypack example to jspm version.

Skypack demo

jspm demo

Skypack example works as expected but jspm example throws that error:

Uncaught SyntaxError: The requested module 'preact/hooks' does not provide an export named 'default' sandbox:1:-33

reactivue package internally imports preact/hooks but jspm trying to import its default export which is not exist.

guybedford commented 3 years ago

Thanks for posting the issue. This was actually a bug in the generator - I've posted up a fix so if you refresh the generator it should be correctly generating the map now.

The corresponding sandbox demo is here.

Unfortunately it's showing another error now - process is not defined.

This seems like a bug in reactivue to me, in that it is assuming the process global exists in an ES module, when it does not exist in the browser - see https://unpkg.com/reactivue@0.3.4/preact/index.esm.js. I'd suggest posting an issue to reactivue here as JSPM will not be supporting rewriting process in the name of ensuring we can move towards browser compat ESM - we shouldn't be shimming Node.js things.

The better pattern to use in ESM for production / development splits is the "production" and "development" exports conditions (https://nodejs.org/dist/latest-v15.x/docs/api/packages.html#packages_conditions_definitions).

If you're able to post an issue back to reactivue that would be great, let me know if I can help further too.

sibbng commented 3 years ago

Hi, thanks for quick fixing the issue. First of all I'm the maintainer of reactivue. There is a thing you missing:

I manually edited import map to map reactivue to index.module.js and it works as expected now.

Working sandbox

To clarify, I was expecting import map generator to pick that browser field while adding it.

guybedford commented 3 years ago

@sibbng you need to put the "browser" entry first, because the exports conditions match in object order.

The 0.4.1 is coming through now, there's just a slight delay for JSPM to process new versions that are released, usually around 20 minutes.

sibbng commented 3 years ago

@sibbng you need to put the "browser" entry first, because the exports conditions match in object order.

Hi, I updated reactivue based on your comment. Now import map generator picks right export.

Thanks for your help and quick fix 🤗