{"record":{"id":"7ccd9b0d89a230b0","repo":"remix-run/react-router","slug":"the-vitejs-plugin-rsc-plugin-should-be-placed-a","errorCode":null,"errorMessage":"The \"@vitejs/plugin-rsc\" plugin should be placed after the React Router RSC plugin in your Vite config","messagePattern":"The \"@vitejs/plugin-rsc\" plugin should be placed after the React Router RSC plugin in your Vite config","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-router-dev/vite/plugins/validate-plugin-order.ts","lineNumber":21,"sourceCode":"export function validatePluginOrder(): Vite.Plugin {\n  return {\n    name: \"react-router:validate-plugin-order\",\n    configResolved(viteConfig) {\n      let pluginIndex = (pluginName: string | string[]) => {\n        pluginName = Array.isArray(pluginName) ? pluginName : [pluginName];\n        return viteConfig.plugins.findIndex((plugin) =>\n          pluginName.includes(plugin.name),\n        );\n      };\n\n      let reactRouterRscPluginIndex = pluginIndex(\"react-router/rsc\");\n      let viteRscPluginIndex = pluginIndex(\"rsc\");\n      if (\n        reactRouterRscPluginIndex >= 0 &&\n        viteRscPluginIndex >= 0 &&\n        reactRouterRscPluginIndex > viteRscPluginIndex\n      ) {\n        throw new Error(\n          `The \"@vitejs/plugin-rsc\" plugin should be placed after the React Router RSC plugin in your Vite config`,\n        );\n      }\n\n      let reactRouterPluginIndex = pluginIndex([\n        \"react-router\",\n        \"react-router/rsc\",\n      ]);\n      let mdxPluginIndex = pluginIndex(\"@mdx-js/rollup\");\n      if (mdxPluginIndex >= 0 && mdxPluginIndex > reactRouterPluginIndex) {\n        throw new Error(\n          `The \"@mdx-js/rollup\" plugin should be placed before the React Router plugin in your Vite config`,\n        );\n      }\n    },\n  };\n}\n","sourceCodeStart":3,"sourceCodeEnd":39,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/react-router-dev/vite/plugins/validate-plugin-order.ts#L3-L39","documentation":"Thrown from the configResolved hook of the react-router:validate-plugin-order plugin when both `react-router/rsc` and `@vitejs/plugin-rsc` (plugin name `rsc`) are present in the Vite config and the React Router RSC plugin appears BEFORE @vitejs/plugin-rsc. React Router's RSC plugin must run earlier so that @vitejs/plugin-rsc receives already-processed RSC module graph.","triggerScenarios":"In vite.config.ts the user registers plugins in the order [reactRouter(), rsc()] but somehow the resolved plugin array has `rsc` before `react-router/rsc`. More commonly: the user places @vitejs/plugin-rsc() above reactRouter() in the plugins array, OR plugin aliasing/merging reorders them.","commonSituations":"Following a tutorial that lists plugin-rsc before react-router. Copy-pasting an RSC example config without preserving order. Wrapping plugins in a helper that flattens/sorts them. Upgrading to RSC Framework Mode from an older sample.","solutions":["In vite.config.ts, ensure reactRouter() (which contains the react-router/rsc sub-plugin) is listed BEFORE pluginRsc(): `plugins: [reactRouter(), pluginRsc()]`.","After editing, run `pnpm dev` or `pnpm build` to re-trigger configResolved and confirm the error is gone.","Remove any plugin-sorting/flattening helpers in the config that reorder the array.","Verify you are not double-registering plugin-rsc via a preset or framework preset that injects it earlier."],"exampleFix":"// vite.config.ts\n// before\nimport { reactRouter } from '@react-router/dev/vite';\nimport { rsc } from '@vitejs/plugin-rsc';\nexport default defineConfig({ plugins: [rsc(), reactRouter()] });\n// after\nexport default defineConfig({ plugins: [reactRouter(), rsc()] });","handlingStrategy":"validation","validationCode":"// static check of plugin order before running vite\nimport { reactRouter } from '@react-router/dev/vite';\nimport { rsc } from '@vitejs/plugin-rsc';\nconst plugins = [reactRouter(), rsc()];\nconst rrIdx = plugins.findIndex((p) => (p.name ?? '').includes('react-router/rsc'));\nconst rscIdx = plugins.findIndex((p) => (p.name ?? '') === 'rsc');\nif (rrIdx >= 0 && rscIdx >= 0 && rrIdx > rscIdx) throw new Error('reactRouter() must come before rsc()');","typeGuard":"function pluginsOrderedCorrectly(plugins: { name: string }[]): boolean {\n  const rr = plugins.findIndex((p) => p.name.includes('react-router/rsc'));\n  const rsc = plugins.findIndex((p) => p.name === 'rsc');\n  return !(rr >= 0 && rsc >= 0 && rr > rsc);\n}","tryCatchPattern":null,"preventionTips":["Treat plugin order in vite.config.ts as load-bearing: reactRouter() first, then rsc().","Add a CI grep that asserts the order of these plugin imports.","Avoid helpers that flatten or sort the plugins array."],"tags":["vite","rsc","plugin-order","config"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}