react-router
react-router copied to clipboard
ENABLE_DEV_WARNINGS is true in production since v7.0.2 due to always-resolving development build
Reproduction
You can reproduce this issue using the following environment:
- https://stackblitz.com/edit/github-fpqca3jn
Steps:
- Open the StackBlitz project
- Run the following commands in the terminal:
npm run build && npm run start - Visit a non-existent URL, such as
/abc - You will see the following development-only warning in the console:
GET / 200 - - 57.135 ms
Error: No route matches URL "/abc"
at getInternalRouterError (file:///home/projects/github-fpqca3jn/node_modules/react-router/dist/development/chunk-C37GKA54.mjs:4731:5)
at Object.query (file:///home/projects/github-fpqca3jn/node_modules/react-router/dist/development/chunk-C37GKA54.mjs:2892:19)
at handleDocumentRequest (file:///home/projects/github-fpqca3jn/node_modules/react-router/dist/development/chunk-KIUJAIYX.mjs:1344:40)
at requestHandler (file:///home/projects/github-fpqca3jn/node_modules/react-router/dist/development/chunk-KIUJAIYX.mjs:1259:24)
No routes matched location "/abc"
GET /abc 404 - - 20.615 ms
System Info
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@react-router/dev: ^7.7.1 => 7.7.1
@react-router/node: ^7.7.1 => 7.7.1
@react-router/serve: ^7.7.1 => 7.7.1
react-router: ^7.7.1 => 7.7.1
vite: ^6.3.3 => 6.3.5
Used Package Manager
npm
Expected Behavior
When running in a production environment (NODE_ENV=production), development-only warnings like No routes matched location should not be shown.
The internal flag ENABLE_DEV_WARNINGS should be false, and the production build (dist/production) should be used.
Actual Behavior
Even with a production build and NODE_ENV=production, accessing a route that does not exist (e.g. /abc) prints the following development warning:
No routes matched location "/abc"
This is caused by dist/development being resolved instead of dist/production, which sets:
ENABLE_DEV_WARNINGS = true
As a result, development-only logs are shown in production.
Additional Context
This issue appears to have been introduced in PR #12437, which modified the exports field in package.json to always point to the development build for Node.js environments:
Oh, good find. I was just dealing with this today too, thanks for all the extra context around why this is happening!
We also get this in all builds, regardless of how we force our builds into production
Not ideal, but was able to get around it by aliasing the imports in my production vite config to point to the production dist:
resolve: {
alias: {
...
'react-router/dom': '/node_modules/react-router/dist/production/dom-export',
'react-router': '/node_modules/react-router/dist/production/index'
}
}
It stopped the development console.logs from showing up, and shaved 1713 bytes off the final bundle.
YMMV