Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

?module should not 404 #278

Closed
akre54 opened this issue Oct 19, 2020 · 4 comments
Closed

?module should not 404 #278

akre54 opened this issue Oct 19, 2020 · 4 comments

Comments

@akre54
Copy link

akre54 commented Oct 19, 2020

Hi there - I'm trying to load @tensorflow/tfjs as a module from unpkg. Adding the ?module flag correctly transpiles all of the import requests for all dependencies except for the package seedrandom. Visiting https://unpkg.com/seedrandom@2.4.4?module gets back a 404, which causes the whole import to fail. I feel like in this case ?module should just fall through to the un-transpiled version, correct?

I opened tensorflow/tfjs#4087 to bump the version, but I have to imagine this impacts other places too.

@j-f1
Copy link

j-f1 commented Oct 19, 2020

As far as I know, unpkg does not do any transpiling besides altering the URLs of modules imported by an ES Module script. In this case, the seedrandom package does not provide an ES Module build (see davidbau/seedrandom#72) so there is no way to fix this without a new version of that package.

@akre54
Copy link
Author

akre54 commented Oct 19, 2020

I guess I'm wondering why adding ?module should 404.

Shouldn't the default behavior be to serve the index package?

@j-f1
Copy link

j-f1 commented Oct 20, 2020

That wouldn’t work. ?module will either output an ES Module file that can be used by native ES Module implementations, or 404. If it were to serve a CommonJS/AMD/etc module, it would result in clients getting an empty exports object, which is not useful.

@akre54
Copy link
Author

akre54 commented Oct 20, 2020

Good point - I guess the only fix is to make all dependencies esm-aware, which kinda sucks.

I guess as a fallback this could rely on the global Math.seedrandom instead if the module fails, but it's probably not worth the hassle. Seems like the platform level needs to mature a bit more.

@akre54 akre54 closed this as completed Oct 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants