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

Properly initialize NODE_ENV if not already set #12578

Merged
merged 2 commits into from
Dec 18, 2024

Conversation

brophdawg11
Copy link
Contributor

It seems React 19 is a bit more strict with NODE_ENV and when it's not set by the user there is currently a mismatch between our code and React's code (similar to the issue in #12078)

  • We default to production when we call vite.resolveConfig in in plugin.ts
  • But React defaults to development

This mismatch causes issues because we end up with mismatched versions of React in the bundle versus the react-router build runtime.

This PR updates the react-router and react-router-serve to set NODE_ENV accordingly if it's not already set:

  • react-router dev defaults to development
  • All other react-router * commands default to production
  • react-router-serve defaults to production

Closes #12138, #12078

Copy link

changeset-bot bot commented Dec 18, 2024

🦋 Changeset detected

Latest commit: 096be72

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
@react-router/dev Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch
react-router Patch
react-router-dom Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@brophdawg11 brophdawg11 changed the base branch from dev to release-next December 18, 2024 19:24
@brophdawg11 brophdawg11 merged commit 1907596 into release-next Dec 18, 2024
8 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/node-env2 branch December 18, 2024 19:46
Copy link
Contributor

🤖 Hello there,

We just published version 7.1.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@Master-Hash
Copy link

let args = arg({}, { argv: process.argv.slice(2) });

@brophdawg11 I believe this line breaks the case where extra args are used, like: react-router dev --host is broken while react-router dev works.

My traceback:

> react-router dev --host

C:\Users\hash\Desktop\xxxx\node_modules\.pnpm\arg@5.0.2\node_modules\arg\index.js:132
                                                throw new ArgError(
                                                ^

ArgError: unknown or unexpected option: --host
    at arg (C:\Users\hash\Desktop\taup\node_modules\.pnpm\arg@5.0.2\node_modules\arg\index.js:132:13)
    at Object.<anonymous> (C:\Users\hash\Desktop\taup\node_modules\.pnpm\@react-router+dev@7.1.0-pre.0_@react-router+serve@7.1.0-pre.0_react-router@7.1.0-pre.0_react-_mucta3rnhylaso2md7vpehy4fa\node_modules\@react-router\dev\bin.js:8:12)   
    at Module._compile (node:internal/modules/cjs/loader:1566:14)
    at Object..js (node:internal/modules/cjs/loader:1718:10)
    at Module.load (node:internal/modules/cjs/loader:1305:32)
    at Function._load (node:internal/modules/cjs/loader:1119:12)
    at TracingChannel.traceSync (node:diagnostics_channel:322:14)
    at wrapModuleLoad (node:internal/modules/cjs/loader:220:24)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:151:5)
    at node:internal/main/run_main_module:33:47 {
  code: 'ARG_UNKNOWN_OPTION'
}

Copy link
Contributor

🤖 Hello there,

We just published version 7.1.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

@connorjs
Copy link

See #12606 which claims this is the root cause for breaking arg parsing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants