Skip to content

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

Merged
merged 2 commits into from
Feb 13, 2018
Merged

umd build fix #564

merged 2 commits into from
Feb 13, 2018

Conversation

franckamayou
Copy link
Contributor

@franckamayou franckamayou commented Jan 30, 2018

What kind of change does this PR introduce?

  • bugfix
  • feature
  • refactoring / style
  • build / chore
  • documentation

Did you add tests for your changes?

  • Yes, my code is well tested
  • Not relevant

If relevant, did you update the documentation?

  • Yes, I've updated the documentation
  • Not relevant

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 webpack externals: { "react" : "react" }, it will return an error Uncaught Error: Cannot find module "react". since React is not available as a module but instead as a global object. Using externals: { "react" : "React" } instead will actually make Webpack fail to build, since the import 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.

@codecov
Copy link

codecov bot commented Jan 30, 2018

Codecov Report

Merging #564 into master will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@           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.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update d4e7763...a768f74. Read the comment docs.

@okonet
Copy link
Collaborator

okonet commented Jan 31, 2018

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.

@franckamayou
Copy link
Contributor Author

Updated the PR description. Let me know if this is clear enough.

@rxmarbles
Copy link
Collaborator

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

externals: {
  "react": {
    root: 'React',
    commonjs2: 'react',
    commonjs: 'react',
    amd: 'react'
  }
}

that way when webpack creates the bundle to should look for each of those and use the one accessible
@okonet what do you think?

@okonet
Copy link
Collaborator

okonet commented Jan 31, 2018

Yes, I agree.

@okonet
Copy link
Collaborator

okonet commented Jan 31, 2018

Can you please try following the official way and check if it solves it?

@franckamayou
Copy link
Contributor Author

franckamayou commented Jan 31, 2018

Sure thing, I'll let you know when I update the PR then

@franckamayou franckamayou force-pushed the umd-fix branch 3 times, most recently from 4a99176 to a27dd66 Compare February 1, 2018 16:34
@franckamayou
Copy link
Contributor Author

I've updated the PR, tested and verified that it works with my application.

Copy link
Collaborator

@okonet okonet left a 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!

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

Successfully merging this pull request may close these issues.

3 participants