{"id":"bf88837022859c96","repo":"vitejs/vite","slug":"renderlegacychunks-and-rendermodernchunks-cann","errorCode":null,"errorMessage":"`renderLegacyChunks` and `renderModernChunks` cannot be both false","messagePattern":"`renderLegacyChunks` and `renderModernChunks` cannot be both false","errorType":"validation","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugin-legacy/src/index.ts","lineNumber":218,"sourceCode":"\nfunction resolveLegacyBuildMinify(\n  minify: BuildOptions['minify'],\n  supportsOxc: boolean | undefined,\n): BuildOptions['minify'] {\n  const usesOxc = supportsOxc && (minify === 'oxc' || minify === true)\n  return usesOxc ? 'oxc' : minify ? 'terser' : false\n}\n\nfunction viteLegacyPlugin(options: Options = {}): Plugin[] {\n  let config: ResolvedConfig\n  let targets: Options['targets']\n  const modernTargets: Options['modernTargets'] =\n    options.modernTargets || modernTargetsBabel\n\n  const genLegacy = options.renderLegacyChunks !== false\n  const genModern = options.renderModernChunks !== false\n  if (!genLegacy && !genModern) {\n    throw new Error(\n      '`renderLegacyChunks` and `renderModernChunks` cannot be both false',\n    )\n  }\n\n  const debugFlags = (process.env.DEBUG || '').split(',')\n  const isDebug =\n    debugFlags.includes('vite:*') || debugFlags.includes('vite:legacy')\n\n  const assumptions = options.assumptions || {}\n\n  const facadeToLegacyChunkMap = new Map()\n  const facadeToLegacyImportMap = new Map<string | null, Rollup.OutputAsset>()\n  const facadeToLegacyPolyfillMap = new Map()\n  const facadeToModernPolyfillMap = new Map()\n  const modernPolyfills = new Set<string>()\n  const legacyPolyfills = new Set<string>()\n  // When discovering polyfills in `renderChunk`, the hook may be non-deterministic, so we group the\n  // modern and legacy polyfills in a sorted chunks map for each rendered outputs before merging them.","sourceCodeStart":200,"sourceCodeEnd":236,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/plugin-legacy/src/index.ts#L200-L236","documentation":"Thrown synchronously when viteLegacyPlugin() is called with both renderLegacyChunks: false and renderModernChunks: false. Since both default to true, this only triggers when a developer explicitly sets both to false. With neither chunk variant being generated, the plugin would have nothing to do, so it fails fast rather than producing a silently empty build.","triggerScenarios":"Calling legacy({ renderLegacyChunks: false, renderModernChunks: false }) in the plugins array of vite.config.ts. Both options default to true, so this requires explicitly disabling both.","commonSituations":"A developer wants to disable legacy output temporarily for debugging or CI speed, sets renderLegacyChunks: false, and then also sets renderModernChunks: false thinking the plugin should be fully inert. Or a conditional config spread accidentally merges both to false.","solutions":["If you want to disable the plugin entirely, remove it from the plugins array conditionally instead of setting both flags to false.","If you only want modern chunks, set renderLegacyChunks: false and leave renderModernChunks at its default (true).","If you only want legacy chunks, set renderModernChunks: false and leave renderLegacyChunks at its default (true)."],"exampleFix":"// before\nplugins: [\n  legacy({ renderLegacyChunks: false, renderModernChunks: false })\n]\n// after — to fully disable, remove the plugin conditionally\nplugins: [\n  ...(shouldUseLegacy ? [legacy()] : [])\n]","handlingStrategy":"validation","validationCode":"function validateLegacyOptions(options) {\n  const genLegacy = options.renderLegacyChunks !== false\n  const genModern = options.renderModernChunks !== false\n  if (!genLegacy && !genModern) {\n    throw new Error('At least one of renderLegacyChunks or renderModernChunks must be true (or left at default)')\n  }\n}\n// call before: validateLegacyOptions(legacyOptions)","typeGuard":"function hasValidRenderOptions(options: Options): boolean {\n  const genLegacy = options.renderLegacyChunks !== false\n  const genModern = options.renderModernChunks !== false\n  return genLegacy || genModern\n}","tryCatchPattern":"try {\n  if (!hasValidRenderOptions(opts)) {\n    throw new Error('Invalid plugin-legacy options')\n  }\n  plugins.push(legacy(opts))\n} catch (e) {\n  console.error('Failed to configure plugin-legacy:', e.message)\n}","preventionTips":["Never set both renderLegacyChunks and renderModernChunks to false — remove the plugin instead.","Use a helper function or schema validation (e.g., zod) for plugin options in CI.","Document your config decisions so other developers don't accidentally disable both."],"tags":["plugin-legacy","config","validation","options"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}