nx: HMR super slow with React project since 15.6.0
Current Behavior
Up until our last migration to 15.6.0 (we were in 15.5.1), adding a console.log somewhere in the code was compiling in less than a second and was added to our browser project without any refresh.
Since the update to 15.6.0 the compilation takes something like 8s and force a refresh of our browser page.
Expected Behavior
We would like the compilation to take the same time that before the migration and that the page is not “forced-refresh”.
Github Repo
https://github.com/Qovery/console
Steps to Reproduce
- fetching a branch before the migration (eg: main),
rm -rf node_modules yarn.lock && yarn - add a
console.loganywhere and see how long the terminal takes to compile - do the same from a branch with the migration on (ex: staging)
Nx Report
> NX Report complete - copy this into the issue template
Node : 19.0.1
OS : darwin arm64
yarn : 1.22.17
nx : 15.0.3
@nrwl/angular : Not Found
@nrwl/cypress : 15.0.3
@nrwl/detox : Not Found
@nrwl/devkit : 15.0.3
@nrwl/esbuild : Not Found
@nrwl/eslint-plugin-nx : 15.0.3
@nrwl/expo : Not Found
@nrwl/express : Not Found
@nrwl/jest : 15.0.3
@nrwl/js : 15.0.3
@nrwl/linter : 15.1.0
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : 15.0.2
@nrwl/nx-plugin : Not Found
@nrwl/react : 15.0.3
@nrwl/react-native : Not Found
@nrwl/rollup : 15.0.3
@nrwl/schematics : Not Found
@nrwl/storybook : 15.0.3
@nrwl/web : 15.0.3
@nrwl/webpack : 15.0.3
@nrwl/workspace : 15.0.3
typescript : 4.8.4
---------------------------------------
Local workspace plugins:
---------------------------------------
Community plugins:
Failure Logs
No response
Additional Information
No response
About this issue
- Original URL
- State: closed
- Created a year ago
- Reactions: 9
- Comments: 18 (2 by maintainers)
We’ll patch it for 15.6 and it’ll be in the next 15.7 release as well.
I’ll look into it. The problem could be the wrong env being set in the executor.
After updating from 15.4.2 to 15.6.2 I can confirm the exact behavior of not having the NODE_ENV set. Of course, it can be set manually, but, I would say, this is a regression in previously working behavior.
Also, for me, this version either changes nothing, since with the extended webpack config, the full-page-reload occurs, instead of HMR.
I think I maybe figured what is the root cause when I noticed my ReactQuery DevTools not showing up:
The process.env.NODE_ENV is undefined, which leads to HMR being disabled as it is running in production mode. That is maybe why everything is so slow. Possibly other env variables are also undefined, haven’t checked.
Edit: there is already an issue about this #14547
This doesn’t work for me. Every time I try to add
NODE_ENV, either via env file or directly in the script call likeNODE_ENV=development nx serve apporcross-env NODE_ENV=development nx serve app(as suggested by @PointSingularity), it unsets the variable again and doesn’t reach the React app. Any ideas why this could happen? I’m using15.6.2, but also tried with15.4.6(first version introducing the problem withNODE_ENVresolving toundefinedin React) and other15.5.xversions and still no effect.For context, I’m using the following config in
project.jsonfor theserveandbuildcommands (none get theNODE_ENVvar in the above versions, unlike in version<= 15.4.5where it works):@nemonemi - I had this same issue, but setting
NODE_ENVand updating my custom webpack config to follow the new example in https://nx.dev/packages/webpack/documents/webpack-config-setup#configure-webpack-for-react-projects fixed it.Side note for anyone that cares, I only have a custom webpack conf to add fallbacks for nodejs core modules since 15.4.6 also removed the polyfills that had been included. I get that that makes it consistent with what webpack 5 does, but it was a breaking change included in a patch version release.
Thanks for the hint. I was able to manually set the
developmentvariable in our package.json start script and HMR is behaving as expected. Good workaround for the time being.package.json
Yes I saw that, and I understand that it could be an interesting lead, but I have not touched anything webpack related in my project… Let’s see if other people get the same issue after migrating, for now, I postponed a little bit our migration. If you want I try anything else tell me and I will!
Have the same issue. The webpack config is the default one.