{"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":"validation","errorClass":null,"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/6beaca39526d5716c3c112ebb0782765baa5a9ce/packages/react-router-dev/vite/plugins/validate-plugin-order.ts#L3-L39","documentation":"In RSC Framework Mode (`unstable_reactRouterRSC`), plugin order matters: the React Router RSC plugin (`react-router/rsc`) must come before `@vitejs/plugin-rsc` (`rsc`) in the plugins array so RR can register its virtual modules and transforms ahead of the RSC compiler. A `validate-plugin-order` plugin compares plugin indices in `configResolved` and throws when `@vitejs/plugin-rsc` is placed first.","triggerScenarios":"Adding `rsdc()`/`@vitejs/plugin-rsc()` to `plugins: [...]` before `reactRouter({ unstable_reactRouterRSC: ... })`; auto-generated configs or templates inserting the RSC plugin at the top; spreading user plugins before the RR plugin in a shared config.","commonSituations":"Hand-editing vite.config.ts while trying RSC mode; copying plugin arrays from docs where order was different; merging configs where `...restPlugins` lands ahead of `reactRouter()`.","solutions":["Reorder vite.config.ts so `reactRouter()` comes first and `@vitejs/plugin-rsc()` after it","Use the RSC template (`rsc-vite-framework`) as the reference ordering","Also verify `@mdx-js/rollup` sits before the React Router plugin if present (checked in the same validator)"],"exampleFix":"// before (vite.config.ts)\nplugins: [rsc(), reactRouter()],\n\n// after\nimport { reactRouter } from '@react-router/dev/vite';\nimport { rsc } from '@vitejs/plugin-rsc';\nplugins: [reactRouter(), rsc()],","handlingStrategy":"validation","validationCode":"// Assert plugin order before exporting the config\nconst plugins = [mdx(), reactRouter(), rsc()];\nconst idx = (name: string) => plugins.findIndex((p: any) => p.name?.includes(name));\nif (idx('rsc') >= 0 && idx('rsc') < idx('react-router')) {\n  throw new Error('@vitejs/plugin-rsc must come after reactRouter()');\n}\nif (idx('@mdx-js/rollup') >= 0 && idx('@mdx-js/rollup') > idx('react-router')) {\n  throw new Error('@mdx-js/rollup must come before reactRouter()');\n}\nexport default defineConfig({ plugins });","typeGuard":null,"tryCatchPattern":"try {\n  await build();\n} catch (e) {\n  if (e instanceof Error && e.message.includes('should be placed after')) {\n    // reorder plugins per the message and rebuild\n  }\n}","preventionTips":["Use the official RSC template's plugin ordering as canonical","Put `mdx()` first, `reactRouter()` next, `rsc()` last in RSC Framework Mode","Re-run `react-router typegen` after any config reorder to catch it cheaply"],"tags":["vite","plugin-order","rsc","config"],"backgroundTag":"vite-plugin-order","analyzedSha":"6beaca39526d5716c3c112ebb0782765baa5a9ce","analyzedAt":"2026-08-18T18:04:14.938Z","contentChangedAt":"2026-08-18T18:04:14.938Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}