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

Production build not minified #3134

Closed
1 task done
tweeres04 opened this issue Oct 19, 2017 · 23 comments
Closed
1 task done

Production build not minified #3134

tweeres04 opened this issue Oct 19, 2017 · 23 comments

Comments

@tweeres04
Copy link

  • I have searched the issues of this repository and believe that this is not a duplicate.

Expected Behavior

When I'm deploying a production build, I should have minified javascript code in order to minimize file size and maximize performance.

Current Behavior

My app.js is 529KB and not minified

Steps to Reproduce (for bugs)

  1. next build
  2. next start

OR

  1. next build
  2. next export

Context

I wanted to use next.js in order to have a lightning fast site as advertised but no minification kills that. I'm sure I'm missing something simple.

Your Environment

Tech Version
next 4.1.1
node 8.4.0
OS MacOS Sierra 10.12.6
browser Chrome
etc React and react-dom 16
@liweinan0423
Copy link
Contributor

Can you confirm your NODE_ENV is set to production? I guess you may have a global environment variable NODE_ENV set and next scripts would honor the user defined ENV if there is one

@mcansh
Copy link
Contributor

mcansh commented Oct 20, 2017

i thinks he's referring to

Uncaught Error: React is running in production mode, but dead code elimination has not been applied. Read how to correctly configure React for production: https://fb.me/react-perf-use-the-production-build

@tweeres04
Copy link
Author

@liweinan0423 Yes, confirmed that NODE_ENV is production.

@mcansh Yes, I'm getting that!

@mcansh
Copy link
Contributor

mcansh commented Oct 20, 2017

Looks like a 4.1.1 issue as it’s not happening in 4.1.0

@timneutkens
Copy link
Member

timneutkens commented Oct 20, 2017

Did a new release (4.1.2) can you try updating?

@mcansh
Copy link
Contributor

mcansh commented Oct 20, 2017

looks good 👍

@timneutkens
Copy link
Member

Thanks for verifying @mcansh 👌

@tweeres04
Copy link
Author

Looks good! Thanks for your quick response @timneutkens!

@zhaihaoran
Copy link

it`s still a issue for me next@4.2.1,the same question happened on the Production enviroment, need help

@ilionic
Copy link

ilionic commented Dec 19, 2017

Confirm, getting the same on 4.2.1

@rgbkrk
Copy link
Contributor

rgbkrk commented Dec 31, 2017

Yep, this is worth reopening. I believe React changed their strategy with 16.2.0.

@timneutkens
Copy link
Member

@rgbkrk @ilionic will be fixed when a new version of canary is released. Also will be fixed once and for all when universal webpack lands (currently working on this).

@devmetal
Copy link

Getting same on 4.2.3

The error is:

React is running in production mode, but dead code elimination has not been applied.

@ilionic
Copy link

ilionic commented Jan 17, 2018

@devmetal should be gone in latest canary version. Although getting app.js size twice as large compared to next.js 3 Investigating..

@devmetal
Copy link

devmetal commented Jan 17, 2018

@ilionic Thank you for quick answer :) Its working! You made my day! 🥇
Working with: next@4.4.0-canary.3

@nosdoska
Copy link

nosdoska commented Jan 26, 2018

I'm getting this in 4.2.3 using a custom server and routing. Trying to update to the canary version now to test.

Edit:
Is working now. I'm a little intrigued now by using a canary version. It is ready for production? Or is better to wait for a release?

@devmetal
Copy link

@dazjavier I use it for production with custom server and routing, everything is working fine. No bad experience. Maybe a little bit slower in development mode, but its not big issue, and my stack also a little bit heavy, firebase, apollo, etc so maybe that cause this. Anyway, in production is working as expected :)

@nosdoska
Copy link

@devmetal Thanks for the information. I've using it for 3 days now, and everything works great. No big performance issues for now.
Thank you.

@cernadasjuan
Copy link

I am using the 5.0.0 version, and I am getting this error again

@davecarlson
Copy link
Contributor

@timneutkens can this be reopened ?

@timneutkens
Copy link
Member

It's extremely hard to get this message with v5. The only way I'm aware of is removing the react aliases in your next.config.js.
Earlier today someone on slack said he saw the warning.
Turned out he had this in his next.config.js:

if (config.resolve.alias) {
      delete config.resolve.alias.react
      delete config.resolve.alias['react-dom']
    }

To be clear. React doesn't require minification anymore. If you're using React 16+ the React is already minified when published on npm, the message is purely to point out that there might be something wrong with the transpilation. In our case we made the choice to not minify minified code and alias to the right bundle in dev/prod automatically. This saves ~20seconds with builds for us in production. And we avoid doing unneeded work.

If you removed the aliases because you have code using react-dom/server on the client side you can upgrade to next@canary which will be released as master soon 🙏

@arunoda
Copy link
Contributor

arunoda commented Feb 9, 2018

And here's that canary version: https://github.com/zeit/next.js/releases/tag/5.0.1-canary.2

@davecarlson
Copy link
Contributor

@timneutkens - you are correct. I'd actually done some next.config optimisations between me posted and you posting, removing the alias lines ) - and that does fix it :)

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

No branches or pull requests