Prioritize ES5 (main) over ES6 (module) in webpack resolve.mainFields config [build failures are irrelevant] #5005
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Since Webpack by default loads from
module
instead ofmain
inpackage.json
, any library that publishes both ES5 and ES6 this way will trigger minification errors withcreate-react-app
.But if we change the Webpack config to try
main
first, libraries that publish both ES5 and ES6 won't have this problem, andcreate-react-app
will still do its best on libraries that only have ES6.I'm really surprised no one has made this change already. Others have suggested this change yet I thought of it independently, so I would think it's obvious.
Here's how I came upon this, devised my fix and verified that it works:
material-ui-render-props-styles
package, which publishes both ES5 and ES6, reported problems withcreate-react-app
and gave me an example repo: https://github.com/solayao/dizzy_comic_feyarn build
has the minification errornpm edit react-scripts
(I tried linking in my fork, but a few too many things had changed from the version the project was using)mainFields: ['browser', 'main', 'module']
to itswebpack.config.prod.js
resolve
configurationyarn build
-- it worked!