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

react-scripts@2.0 takes forever to build #5068

Closed
lamngo255 opened this issue Sep 23, 2018 · 20 comments
Closed

react-scripts@2.0 takes forever to build #5068

lamngo255 opened this issue Sep 23, 2018 · 20 comments

Comments

@lamngo255
Copy link

lamngo255 commented Sep 23, 2018

Recently, I upgraded a CRA project to the latest react-scripts v2 release (2.0.0-next.2150693d), and quickly realized that "yarn build" takes hours to build my project. Seems like it hangs at "Creating an optimized production build" for some reasons. That was quite unexpected since the previous version of react-scripts that I used (v1.1.5) could build the project just fine, though production build took a fairly long time (~15min).

FYI, before I was able to build, I had to manually update eslint to version 5.6.0, because react-scripts v2 requires it and a different version of eslint (3.9.1) detected higher up in the tree isn't compatible with react-scripts@2.0, sorta similar to this known issue. I guess this approach could prevent users from breaking react-scripts initial dev dependency? (link).

Environment

  1. node -v: v8.12.0
  2. npm -v: v6.4.1
  3. yarn -v: (if you use Yarn): v1.9.4
  4. react-scripts: (if you haven’t ejected): 2.0.0-next.2150693d
  5. Ubuntu 16.04 LTS

Expected Behavior

yarn build succeeds

Actual Behavior

Get stuck at "Creating an optimized production build..." forever.

Reproducible Demo

Here's my package.json

@gaearon
Copy link
Contributor

gaearon commented Sep 23, 2018

I don’t think rewires are compatible with 2.x. AFAIK that project is not actively maintained anymore either.

@lamngo255
Copy link
Author

Unfortunately, removing any packages related to react-app-rewired and config-overrides.js didn't seem to work either. I've tried yarn build & yarn start but they both get stuck for hours.

@Timer
Copy link
Contributor

Timer commented Sep 23, 2018

Could you please share this project? Hours seems quite excessive ... how are production build times the second build (without removing node_modules)?

@lamngo255
Copy link
Author

@Timer sorry, it's a private project, so I can't share it. Although I mentioned that it takes hours, in reality, I couldn't complete the production build. Because it takes over 3 hours stucking with "Creating an optimized..." message, so I just shut it down.

The normal build time was ~950s, for react-scripts v1.1.5 + react-app-rewired. If I were to remove rewire packages, I would end up getting this error, which I think was caused by insufficient optimization in react-scripts v1.
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

@Timer
Copy link
Contributor

Timer commented Sep 23, 2018

What is your rewired doing for you?

@Timer
Copy link
Contributor

Timer commented Sep 23, 2018

Please try running GENERATE_SOURCEMAP=false yarn build and see if that completes any faster.

@lamngo255
Copy link
Author

lamngo255 commented Sep 23, 2018

I used rewired for uglifying and vendor splitting. Since react-scripts v1 seems to not support automatic vendor chunking without the latter library, I switched to react-scripts v2.0 to use webpack 4 features, including vendor splitting and terser (uglifyjs) plugin.

@Timer
Copy link
Contributor

Timer commented Sep 23, 2018

I would definitely remove your rewire then with v2, it might be causing some bad configuration.
Please try GENERATE_SOURCEMAP=false yarn build with no rewires applied.

Unfortunately, we're not going to be of much help unless if you can share the project with us privately.

@lamngo255
Copy link
Author

lamngo255 commented Sep 23, 2018

Please try running GENERATE_SOURCEMAP=false yarn build and see if that completes any faster.

Thank @Timer, it's actually significantly faster when using react-scripts v1, down to ~600s. I'll try with react-scripts v2.

It's my company's project, so unfortunately, I don't think sharing the project would be a good idea.

@gaearon
Copy link
Contributor

gaearon commented Sep 23, 2018

You can try completely disabling Terser by temporarily commenting it out in the config. This will tell you whether it’s webpack or Terser that hangs.

You can also try adding webpack’s built in ProfilerPlugin to trace its execution.

@lamngo255
Copy link
Author

Funnily enough, it looked like I was able to build successfully with source map disabled and no wires applied (react-scripts@2.0). The build time was reduced to just ~348s, much faster than what I would've expected. However, there's much more sub 1KB chunk files produced during the process, which I believe will hurt the performance.

"yarn build" with source map enabled remains stuck, but let's see how long it will hang.

@lamngo255
Copy link
Author

You can try completely disabling Terser by temporarily commenting it out in the config. This will tell you whether it’s webpack or Terser that hangs.

You can also try adding webpack’s built in ProfilerPlugin to trace its execution.

Interesting, but how could you enable those configurations in the webpack config file without even ejecting and no rewires? I tried editing webpack.config.prod.js in the node_modules, but I don't think this is a viable option, because the file remains intact whenever I rebuild the project.

@Timer
Copy link
Contributor

Timer commented Sep 23, 2018

Interesting, I'm happy to hear v2 is faster! Can you disable Terser and re-enable sourcemaps and see if the build completes?
I'm curious what part of the sourcemap pipeline is getting stuck.

To edit config, I suggest you commit all changes, eject, and then revert the eject when you're done testing.

@gaearon
Copy link
Contributor

gaearon commented Sep 23, 2018

Sorry, I only meant to suggest editing as a temporary way to try to diagnose the issue. It wouldn’t persist indeed.

@lamngo255
Copy link
Author

lamngo255 commented Sep 24, 2018

It's okay, looks like Terser isn't what causes the hang, the build still gets stuck even when I commented it out. Besides, for unknown reasons, GENERATE_SOURCEMAP=false yarn build won't work after ejecting.

In addition, I was wondering how I could apply other third libraries like ant design without using rewires.

@superandrew213
Copy link

react-scripts@2.0.0-next.a671462c (previous version) works for me. I am using rewired and ant design.

@Timer
Copy link
Contributor

Timer commented Sep 24, 2018

Does upgrading actually break compilation for you @superandrew213? Or are you just on the old version?

@superandrew213
Copy link

superandrew213 commented Sep 24, 2018

@Timer just upgraded to latest react-scripts and react-app-rewired and everything works for me and nothing breaks.

Build is as fast as v1.

@Timer
Copy link
Contributor

Timer commented Sep 26, 2018

#5096 should make this better

@Timer
Copy link
Contributor

Timer commented Sep 26, 2018

Closing since we were not given a reproducing project

@Timer Timer closed this as completed Sep 26, 2018
@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants