Repository navigation
React router 8 importing @react-router/dev/routes in production build #15619
|
I want to deploy a react router 8 app with docker. This is my {
"scripts": {
"build": "react-router build",
"start": "react-router-serve ./build/server/index.js",
},
"dependencies": {
"@react-router/node": "^8.4.0",
"@react-router/serve": "^8.4.0",
"react-router": "^8.4.0",
"react": "^19.3.0",
"react-dom": "^19.3.0",
},
"devDependencies": {
"@react-router/dev": "^8.4.0",
"@tailwindcss/vite": "^4.3.3",
"typescript": "^7.0.2",
"vite": "^8.3.0"
},
}My import type { Config } from '@react-router/dev/config';
export default {
ssr: true,
} satisfies Config;and my import { reactRouter } from '@react-router/dev/vite';
import tailwindcss from '@tailwindcss/vite';
import { defineConfig } from 'vite';
export default defineConfig({
resolve: {
tsconfigPaths: true,
},
plugins: [tailwindcss(), reactRouter()],
});Everything is very similar to the official template https://github.com/remix-run/react-router-templates/tree/main/default Both the official template and I are omitting development dependencies from the final image. They do
But the built file imports it (!): # build/server/index.js
...
import { index, layout, prefix, route } from "@react-router/dev/routes";
...A quick fix will be adding Is it a bug in react-router (& is it supposed to convert routes and use another package?), or it's the documentation being misleading, or is it me using the package wrongly? To give more context, I have many import { index, layout, prefix, route } from '@react-router/dev/routes';
export const settings = [
...prefix('settings', [
layout('./settings/layout.tsx', [
index('./settings/page.tsx'),
route('app', './settings/app/page.tsx'),
]),
]),
];Also asked in StackOverflow, but as you know, their routine is hitting the downvote button instead of being helpful 🙃 |
Replies: 1 comment 1 reply
|
I'd keep Splitting the configuration across files is fine. In Framework Mode, the route configuration describes which route modules to build. A loader, component, or other runtime module importing that configuration introduces a separate dependency on the helpers used to construct it. I tested a small app with React Router /
If you share route information with navigation components or loaders, move the runtime URLs/metadata into a separate module that doesn't import This reproduces one way to get your symptom; I haven't established that it's the cause in your app. Could you share the top-level |
I'd keep
@react-router/devindevDependenciesand check whether a runtime module imports one of your route-config files, directly or through a barrel export.Splitting the configuration across files is fine. In Framework Mode, the route configuration describes which route modules to build. A loader, component, or other runtime module importing that configuration introduces a separate dependency on the helpers used to construct it.
I tested a small app with React Router /
@react-router/dev8.4.0, Vite 8.3.0 and React 19.3.0:app/routes.tsimported a separate settings config usingindex()andprefix(). The server build had no@react-router/dev/routesimport and loaded successfully afternp…