Skip to content

Commit 1907596

Browse files
Properly initialize NODE_ENV if not already set (#12578)
* Properly initialize node env for react-router cli * Properly initialize `NODE_ENV` in `react-router-serve` --------- Co-authored-by: jrestall <james.restall@gmail.com>
1 parent ca0a62c commit 1907596

File tree

4 files changed

+24
-0
lines changed

4 files changed

+24
-0
lines changed

.changeset/selfish-pianos-grab.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@react-router/dev": patch
3+
---
4+
5+
Properly initialize `NODE_ENV` if not already set for compatibility with React 19

contributors.yml

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@
147147
- johnpangalos
148148
- jonkoops
149149
- jrakotoharisoa
150+
- jrestall
150151
- juanpprieto
151152
- jungwoo3490
152153
- kachun333

packages/react-router-dev/bin.js

+13
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
11
#!/usr/bin/env node
2+
let arg = require("arg");
3+
4+
// Minimal replication of our actual parsing in `run.ts`. If not already set,
5+
// default `NODE_ENV` so React loads the proper version in it's CJS entry script.
6+
// We have to do this before importing `run.ts` since that is what imports
7+
// `react` (indirectly via `react-router`)
8+
let args = arg({}, { argv: process.argv.slice(2) });
9+
if (args._[0] === "dev") {
10+
process.env.NODE_ENV = process.env.NODE_ENV ?? "development";
11+
} else {
12+
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
13+
}
14+
215
require("./dist/cli/index");

packages/react-router-serve/bin.js

+5
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
#!/usr/bin/env node
2+
3+
// If not already set, default `NODE_ENV=production` so React loads the proper
4+
// version in it's CJS entry script
5+
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
6+
27
require("./dist/cli");

0 commit comments

Comments
 (0)