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

Prioritize ES5 (main) over ES6 (module) in webpack resolve.mainFields config [build failures are irrelevant] #5005

Closed

Conversation

jedwards1211
Copy link

@jedwards1211 jedwards1211 commented Sep 13, 2018

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:

  1. A user of my material-ui-render-props-styles package, which publishes both ES5 and ES6, reported problems with create-react-app and gave me an example repo: https://github.com/solayao/dizzy_comic_fe
  2. I cloned that repo and installed deps in it, confirmed yarn build has the minification error
  3. 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)
  4. I added mainFields: ['browser', 'main', 'module'] to its webpack.config.prod.js resolve configuration
  5. retried yarn build -- it worked!

@jedwards1211 jedwards1211 changed the title Prioritize ES5 (main) over ES6 (module) in webpack resolve.mainFields config Prioritize ES5 (main) over ES6 (module) in webpack resolve.mainFields config [build failures are irrelevant] Sep 13, 2018
@Timer
Copy link
Contributor

Timer commented Sep 19, 2018

This will be resolved in v2, but thank you for the PR!

We want webpack to resolve module, then main. Jest should resolve straight to main.

@Timer Timer closed this Sep 19, 2018
@jedwards1211
Copy link
Author

jedwards1211 commented Sep 19, 2018

I'm confused, why do you want to resolve module first, given the minification issues?

@Timer
Copy link
Contributor

Timer commented Sep 19, 2018

These issues only exist in v1 -- they're fixed in v2.

@jedwards1211
Copy link
Author

I see. Would it be helpful to make this a patch release to v1 though?

@Timer
Copy link
Contributor

Timer commented Sep 19, 2018

It would be a breaking change so it can't land in v1.

@jedwards1211
Copy link
Author

I get what you mean by that but,

  • as far as I can imagine, anything that this change would affect was already broken
  • what working projects would it actually break? In any package that has both main and module, the main should just be the transpiled form of module and hence should work in its place.

@lock lock bot locked and limited conversation to collaborators Jan 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants