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

UMD builds are not enabled on UNPKG #13450

Open
nickmccurdy opened this issue Aug 21, 2018 · 13 comments
Open

UMD builds are not enabled on UNPKG #13450

nickmccurdy opened this issue Aug 21, 2018 · 13 comments

Comments

@nickmccurdy
Copy link

Visiting https://unpkg.com/react displays the CJS build (https://unpkg.com/react@16.4.2/index.js) when the UMD build (https://unpkg.com/react@16.4.2/umd/react.development.js) should be displayed instead. I also noticed this issue with react-dom, so I assume all packages need to be fixed.

Please refer to the usage instructions at the bottom of https://unpkg.com/.

@gaearon
Copy link
Collaborator

gaearon commented Aug 21, 2018

Please see the discussion in #10597. It’s intentional.

@gaearon gaearon closed this as completed Aug 21, 2018
@nickmccurdy
Copy link
Author

👎 This is anti-beginner in my opinion. It is standard for Unpkg URLs to point to development builds, and we are breaking user expectations. It's much worse for the default URL to literally error because browsers do not support common JS than to serve a development build, which will be displayed in the React Devtools extension anyway.

@nickmccurdy
Copy link
Author

nickmccurdy commented Aug 21, 2018

By the way, if the concern is about the user not knowing the development build is provided by default (which they would probably already know by using other Unpkg packages), Unpkg redirects the user to the full UMD file path, making the path that is used by default clear.

For example, https://unpkg.com/jquery redirects to https://unpkg.com/jquery@3.3.1/dist/jquery.js, which is clearly unminified and build for development.

@gaearon
Copy link
Collaborator

gaearon commented Aug 21, 2018

This is anti-beginner in my opinion.

We've been there before. If React doesn't make this choice then it's "anti-beginner". If React does, then it'll be "anti-performance". Either way somebody will be unhappy. See discussion in #8784. We have to educate developers about the differences between builds, and the only way to do so is to force them to choose one or the other. I think that if you can drop a script tag on the page without thinking about whether it should be a dev or a prod build, we're going to keep seeing sites ship development versions to production, and hurting the user experience.

Unpkg redirects the user to the full UMD file path, making the path that is used by default clear.

Only if you read the redirect result URL.

It is standard for Unpkg URLs to point to development builds, and we are breaking user expectations.

What do you mean by "standard"? Do all libraries do that? For libraries that do, are their DEV builds several times larger and smaller, like React DEV build is?

It's much worse for the default URL to literally error because browsers do not support common JS than to serve a development build

I agree! I don't know why unpkg attempts to serve a CommonJS entry point (which main stands for). Instead it would be great if it served some page that suggested to find the proper UMD build inside.

@gaearon
Copy link
Collaborator

gaearon commented Aug 21, 2018

Unpkg could provide first-class support for multiple explicitly chosen UMD versions.
For example:

https://unpkg.com/react:development
https://unpkg.com/react:production

https://unpkg.com/react-dom:development
https://unpkg.com/react-dom:production

This works with versions too:

https://unpkg.com/react-dom:production@16.4.2

Since : is reserved, it won't cause clashes.

This could work by special fields in package.json, e.g.

  "umd:development": "umd/react.development.js",
  "umd:production": "umd/react.production.js"

For packages that opted into this, unpkg could display a better error page when you attempt to load https://unpkg.com/react directly — and show disambiguating links right there. Seems like best of both worlds to me.

@gaearon
Copy link
Collaborator

gaearon commented Aug 21, 2018

If unpkg is interested in implementing the above, we could do it.

@nickmccurdy
Copy link
Author

I still disagree with not using umd/react.development.js as a stopgap solution, but I like your suggestion as Unpkg does not have a way to choose alternative entry points without knowing the full file path. Maybe it could even 404 to make it very obvious that a package doesn't have a default entry point for both development and production. I'll cross-post an issue.

@joemsak
Copy link

joemsak commented Nov 13, 2018

react@16 is redirecting to 16.6.2 which doesn't seem to exist, and when you go to the CJS version, it says it is version 16.6.1 - which does work on UMD

please excuse me if I don't understand something properly, I am new to using unpkg as per instructions from React documentation

unpkg-react

@joemsak
Copy link

joemsak commented Nov 13, 2018

Sorry for commenting here, I meant to put it in a closed issue on unpkg mjackson/unpkg#38 if folks wouldn't mind letting it stay here for their reference? Otherwise I can delete and move it too. However, FWIW I was following directions here https://reactjs.org/docs/add-react-to-a-website.html

@gaearon
Copy link
Collaborator

gaearon commented Nov 13, 2018

There was a broken release. It's fixed now.

@joemsak
Copy link

joemsak commented Nov 13, 2018

Thank you for the update, and so quickly! I really appreciate that. Cheers

@nickmccurdy
Copy link
Author

Depends on mjackson/unpkg#93

@nickmccurdy
Copy link
Author

The upstream Unpkg issue has been fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants