Created by: jedwards1211
Since Webpack by default loads from module instead of main in package.json, any library that publishes both ES5 and ES6 this way will trigger minification errors with create-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, and create-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:
- A user of my
material-ui-render-props-stylespackage, which publishes both ES5 and ES6, reported problems withcreate-react-appand gave me an example repo: https://github.com/solayao/dizzy_comic_fe - I cloned that repo and installed deps in it, confirmed
yarn buildhas the minification error - Then I ran
npm edit react-scripts(I tried linking in my fork, but a few too many things had changed from the version the project was using) - I added
mainFields: ['browser', 'main', 'module']to itswebpack.config.prod.jsresolveconfiguration - retried
yarn build-- it worked!