{"record":{"id":"33b46107e0ec2003","repo":"remix-run/react-router","slug":"the-mdx-js-rollup-plugin-should-be-placed-befor","errorCode":null,"errorMessage":"The \"@mdx-js/rollup\" plugin should be placed before the React Router plugin in your Vite config","messagePattern":"The \"@mdx-js/rollup\" plugin should be placed before the React Router 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":32,"sourceCode":"      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":14,"sourceCodeEnd":39,"githubUrl":"https://github.com/remix-run/react-router/blob/1fd704a7dabcbe3ae09d7387b460e6acaba30ec1/packages/react-router-dev/vite/plugins/validate-plugin-order.ts#L14-L39","documentation":"Thrown from configResolved of react-router:validate-plugin-order when `@mdx-js/rollup` is present and resolves to a higher index than the React Router plugin (`react-router` or `react-router/rsc`). MDX must transform .mdx files before React Router consumes the module graph, so it must precede React Router in the plugins array.","triggerScenarios":"vite.config.ts lists `mdx()` after `reactRouter()` in the plugins array, so mdxPluginIndex > reactRouterPluginIndex. The check uses findIndex over resolved plugin names containing `@mdx-js/rollup`.","commonSituations":"Adding MDX to an existing React Router app by appending mdx() at the end of plugins. Following docs that show `plugins: [reactRouter(), mdx()]` (wrong order). Using a starter that registered MDX lazily.","solutions":["In vite.config.ts, put mdx() BEFORE reactRouter(): `plugins: [mdx(), reactRouter()]`.","Re-run dev/build to confirm configResolved no longer throws.","If a framework preset injects MDX, ensure the preset runs before React Router or configure the preset order accordingly.","Update @mdx-js/rollup to a version whose plugin.name is still recognized (`@mdx-js/rollup`)."],"exampleFix":"// vite.config.ts\n// before\nimport mdx from '@mdx-js/rollup';\nimport { reactRouter } from '@react-router/dev/vite';\nexport default defineConfig({ plugins: [reactRouter(), mdx()] });\n// after\nexport default defineConfig({ plugins: [mdx(), reactRouter()] });","handlingStrategy":"validation","validationCode":"import mdx from '@mdx-js/rollup';\nimport { reactRouter } from '@react-router/dev/vite';\nconst plugins = [mdx(), reactRouter()]; // assert mdx index < reactRouter index\nconst mdxIdx = plugins.findIndex((p) => p.name.includes('@mdx-js/rollup'));\nconst rrIdx = plugins.findIndex((p) => p.name.includes('react-router'));\nif (mdxIdx >= 0 && rrIdx >= 0 && mdxIdx > rrIdx) throw new Error('mdx() must come before reactRouter()');","typeGuard":"function mdxBeforeReactRouter(plugins: { name: string }[]): boolean {\n  const mdx = plugins.findIndex((p) => p.name.includes('@mdx-js/rollup'));\n  const rr = plugins.findIndex((p) => p.name.includes('react-router'));\n  return !(mdx >= 0 && rr >= 0 && mdx > rr);\n}","tryCatchPattern":null,"preventionTips":["Always register mdx() above reactRouter() in vite.config.ts.","If a preset injects MDX, verify it runs before React Router.","Add a comment in the config documenting the required order."],"tags":["vite","mdx","plugin-order","config"],"backgroundTag":null,"analyzedSha":"1fd704a7dabcbe3ae09d7387b460e6acaba30ec1","analyzedAt":"2026-08-12T13:54:57.804Z","schemaVersion":2},"datasetVersion":"2026-08-12T18:17:37.767Z"}