-
-
Notifications
You must be signed in to change notification settings - Fork 10.3k
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
[Bug]: react-router-serve requires cross-env NODE_ENV=production
#12078
Comments
I think I agree that react-router should match react's behaviour in cases where NODE_ENV is not set though in a vacuum I do think loading the production build would have been a better default for both |
What is the ask here? To add that to the template? Or to Jacob's underkill stack? If the former, would you care to submit a PR? |
I think the ask is for react-router-serve to not set NODE_ENV to production, because react router cannot tell react to run the production build and therefore will be out of sync with it |
Neither, I'd prefer devs don't need to even think about it and we handle setting node_env automatically in Here's my proposed PR fix for the I also found this error is only reproducible with React v19 but even with React v18 the dev react and prod react-dom modules are loaded, it just doesn't hard error. So I think still a good idea to fix. |
I'd prefer aligning our default with Reacts - but will run this by the team. The side-effect nature of the linked PR could make it very tricky to diagnose why React was loading the production build if you were never setting |
What version of React Router are you using?
7.0.0-pre.0
Steps to Reproduce
The userland fix for the error is to always specify NODE_ENV=production in the package.json start script.
This could be because whilst
react-router-serve
tries to default to NODE_ENV=production,react
is loaded earlier than when that code runs and loads thedevelopment
version of react in the absence of a NODE_ENV env variable. Then later the app server build is dynamically imported and subsequently importsreact-dom
, but now NODE_ENV has been set to production byreact-router-serve
, so there is a mismatch in the loaded react libraries with a mix of development and production.react-router/packages/react-router-serve/cli.ts
Line 15 in bc1c1c8
The import chain that results in the
react
development version being loaded is:So should we always pass a NODE_ENV in the start script or is this an issue?
System Info
Expected Behavior
Site returns 200 response.
Actual Behavior
The text was updated successfully, but these errors were encountered: