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 the development version of react in the absence of a NODE_ENV env variable. Then later the app server build is dynamically imported and subsequently imports react-dom, but now NODE_ENV has been set to production by react-router-serve, so there is a mismatch in the loaded react libraries with a mix of development and production.
https://github.com/remix-run/react-router/blob/bc1c1c8ef87b7bf97f1f168604b89a5da61939da/packages/react-router-serve/cli.ts#L15
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
Node: v21.1.0
OS: Mac
Expected Behavior
Site returns 200 response.
Actual Behavior
[react-router-serve] http://localhost:3000 (http://192.168.20.16:3000)
TypeError: dispatcher.getOwner is not a function
at getOwner (/Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react@19.0.0-rc-1460d67c-20241003/node_modules/react/cjs/react.development.js:412:54)
at Module.createElement (/Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react@19.0.0-rc-1460d67c-20241003/node_modules/react/cjs/react.development.js:1331:9)
at mapRouteProperties (file:///Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-router@7.0.0-pre.0_react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241_bnl2udvc6mytkjbq3r7oxas3x4/node_modules/lib/components.tsx:93:22)
at map (file:///Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-router@7.0.0-pre.0_react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241_bnl2udvc6mytkjbq3r7oxas3x4/node_modules/lib/router/utils.ts:454:12)
at Array.map (<anonymous>)
at convertRoutesToDataRoutes (file:///Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-router@7.0.0-pre.0_react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241_bnl2udvc6mytkjbq3r7oxas3x4/node_modules/lib/router/utils.ts:430:17)
at createStaticRouter (file:///Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-router@7.0.0-pre.0_react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241_bnl2udvc6mytkjbq3r7oxas3x4/node_modules/lib/dom/server.tsx:281:20)
at ServerRouter (file:///Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-router@7.0.0-pre.0_react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241_bnl2udvc6mytkjbq3r7oxas3x4/node_modules/lib/dom/ssr/server.tsx:68:16)
at renderWithHooks (/Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241003/node_modules/react-dom/cjs/react-dom-server.node.production.js:3769:18)
at renderElement (/Users/jrestall/Dev/underkill-stack/node_modules/.pnpm/react-dom@19.0.0-rc-1460d67c-20241003_react@19.0.0-rc-1460d67c-20241003/node_modules/react-dom/cjs/react-dom-server.node.production.js:3907:14)
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. https://github.com/remix-run/react-router/blob/bc1c1c8ef87b7bf97f1f168604b89a5da61939da/packages/react-router-serve/cli.ts#L15The 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