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 build doesn't work via import in the browser (TypeError: Cannot set property 'React' of undefined) #14635

Closed
vp2177 opened this issue Jan 19, 2019 · 6 comments
Labels
Component: Build Infrastructure Resolution: Stale Automatically closed due to inactivity

Comments

@vp2177
Copy link

vp2177 commented Jan 19, 2019

When importing the UMD build (both production and development) in the browser – that is, from a <script type="module"> – an error is thrown: TypeError: Cannot set property 'React' of undefined.

The relevant code:

12: (function (global, factory) {
13:	typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
14:	typeof define === 'function' && define.amd ? define(factory) :
15:	(global.React = factory());
16: }(this, (function () { 'use strict';

Throws on line 15 as globalthis is undefined in a module context.
Is this as simple to fix as passing this || self on line 16, or is there a catch?

Do you want to request a feature or report a bug?
bug

What is the current behavior?
TypeError: Cannot set property 'React' of undefined

If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem.
https://jsfiddle.net/dja3wfc7/ (Updated)

What is the expected behavior?
I would expect the import to work, as the same file works if included via <script src=...>.

Which versions of React, and which browser / OS are affected by this issue? Did this work in previous versions of React?
React 16.7.0 (latest stable) – I have found another UMD related bug, #3037, which pertains to React 0.12.2. I have tried that version and indeed it works, it can be imported.
Chrome 71, Safari 12 tested (probably all browsers)

@vp2177 vp2177 changed the title UMD build doesn't work via import (TypeError: Cannot set property 'React' of undefined) UMD build doesn't work via import in the browser (TypeError: Cannot set property 'React' of undefined) Jan 19, 2019
@gaearon
Copy link
Collaborator

gaearon commented Jan 19, 2019

It's not expected that UMD imports would work with import — you want ESM builds (which we don't offer yet).

@vp2177
Copy link
Author

vp2177 commented Feb 7, 2019

@gaearon I have looked into why the UMD build doesn't work, as I thought it should. (Of course an ESM build would be better, but in the meantime...)

It is because rollup ^0.52.1 is used for the build. I haven't tracked down when this was fixed in rollup but the current version (1.1.2) produces a correct UMD, which works in a module context.

Is it feasible to upgrade the rollup dependency, or is there a reason to stick with that old version?

@gaearon
Copy link
Collaborator

gaearon commented Feb 8, 2019

I don't remember a particular reason. If you send a PR upgrading Rollup we can look at it!

@kunukn
Copy link
Contributor

kunukn commented Mar 25, 2019

I don't remember a particular reason. If you send a PR upgrading Rollup we can look at it!

#15037

@stale
Copy link

stale bot commented Jan 10, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the Resolution: Stale Automatically closed due to inactivity label Jan 10, 2020
@stale
Copy link

stale bot commented Jan 17, 2020

Closing this issue after a prolonged period of inactivity. If this issue is still present in the latest release, please create a new issue with up-to-date information. Thank you!

@stale stale bot closed this as completed Jan 17, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Build Infrastructure Resolution: Stale Automatically closed due to inactivity
Projects
None yet
Development

No branches or pull requests

3 participants