-
-
Notifications
You must be signed in to change notification settings - Fork 795
umd build fix #564
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 fix #564
Conversation
Codecov Report
@@ Coverage Diff @@
## master #564 +/- ##
=======================================
Coverage 99.49% 99.49%
=======================================
Files 3 3
Lines 197 197
Branches 56 56
=======================================
Hits 196 196
Misses 1 1 Continue to review full report at Codecov.
|
I'm not sure I'm familiar with this hack. Is it somewhere in docs? Also, what is the problem exactly it solves? Please update the PR description. |
Updated the PR description. Let me know if this is clear enough. |
It is an interesting fix, however I think we should stay inline w/ the webpack documentation which is that if you are going to use react as a script vs in your bundle we should be splitting our component externals the way the stack overflow answer provided
that way when webpack creates the bundle to should look for each of those and use the one accessible |
Yes, I agree. |
Can you please try following the official way and check if it solves it? |
Sure thing, I'll let you know when I update the PR then |
4a99176
to
a27dd66
Compare
I've updated the PR, tested and verified that it works with my application. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please fix the failing build and it’s good to go! Thanks!
What kind of change does this PR introduce?
Did you add tests for your changes?
If relevant, did you update the documentation?
Summary
This pr solves a problem for the umd build with React loaded from the <script> tag as a global library. When including React from the script tag, it is available to the global namespace as the
window.React
object. However, when specifying the external library in webpackexternals: { "react" : "react" }
, it will return an errorUncaught Error: Cannot find module "react".
since React is not available as a module but instead as a global object. Usingexternals: { "react" : "React" }
instead will actually make Webpack fail to build, since theimport React from "react";
statement will not match any module.It appears a solution, based on the comments on the link below (by user jide), is to specify
externals: { "react" : "umd react" }
, which takes care of both cases.Does this PR introduce a breaking change?
Other information
This is a link describing the issue with webpack, packaging with react as an external library and umd.
Another link from stackoverflow with another potential solution.