{"record":{"id":"d03ff8403c9c79ea","repo":"vitejs/vite","slug":"no-corresponding-legacy-entry-chunk-found-for-ht","errorCode":null,"errorMessage":"No corresponding legacy entry chunk found for ${htmlFilename}","messagePattern":"No corresponding legacy entry chunk found for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugin-legacy/src/index.ts","lineNumber":850,"sourceCode":"          tag: 'script',\n          attrs: {\n            nomodule: genModern,\n            crossorigin: true,\n            // we set the entry path on the element as an attribute so that the\n            // script content will stay consistent - which allows using a constant\n            // hash value for CSP.\n            id: legacyEntryId,\n            'data-src': toAssetPathFromHtml(\n              legacyEntryFilename,\n              chunk.facadeModuleId!,\n              config,\n            ),\n          },\n          children: systemJSInlineCode,\n          injectTo: 'body',\n        })\n      } else {\n        throw new Error(\n          `No corresponding legacy entry chunk found for ${htmlFilename}`,\n        )\n      }\n\n      // 6. inject dynamic import fallback entry\n      if (legacyPolyfillFilename && legacyEntryFilename && genModern) {\n        tags.push({\n          tag: 'script',\n          attrs: { type: 'module' },\n          children: detectModernBrowserCode,\n          injectTo: 'head',\n        })\n        tags.push({\n          tag: 'script',\n          attrs: { type: 'module' },\n          children: dynamicFallbackInlineCode,\n          injectTo: 'head',\n        })","sourceCodeStart":832,"sourceCodeEnd":868,"githubUrl":"https://github.com/vitejs/vite/blob/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/plugin-legacy/src/index.ts#L832-L868","documentation":"In `transformIndexHtml`, after the legacy polyfill is handled, plugin-legacy looks up `facadeToLegacyChunkMap.get(chunk.facadeModuleId)` to inject the `<script nomodule data-src=...>` SystemJS entry. If that entry is undefined (no legacy chunk was recorded for this HTML facade), it throws unconditionally when `genLegacy` is true. Unlike the polyfill checks, there is no `.size` guard - a missing legacy entry is always fatal.","triggerScenarios":"Building with `genLegacy` true but the legacy SystemJS bundle was not produced/recorded for the current HTML entry. Common when the legacy build pass (`-legacy` chunk in `transformIndexHtml`) did not run or its `facadeToLegacyChunkMap.set` was never reached for that facade.","commonSituations":"Intercepting/skipping the legacy build pass via custom plugins. Renaming facades or stripping `-legacy` chunks before `transformIndexHtml` runs. Version mismatch where the legacy output structure changed. Multi-entry setups where one entry never received a legacy counterpart.","solutions":["Verify `dist/assets` contains a `-legacy.js` entry for each HTML entry.","Remove plugins that manipulate `chunk.fileName` or skip chunks named with `-legacy`.","If you intentionally disabled legacy generation, set `renderLegacyChunks: false` so `genLegacy` is false and this branch is skipped (it returns early at `if (!genLegacy) return`).","Upgrade @vitejs/plugin-legacy and vite together to compatible versions."],"exampleFix":"// before: a custom plugin deletes the legacy chunk\nrollupOptions: { plugins: [ { name:'strip-legacy', generateBundle(_,b){ for(const k in b) if(k.includes('-legacy')) delete b[k] } } ] },\nplugins: [legacy()],\n// after: don't strip legacy chunks, or disable legacy generation explicitly\nplugins: [legacy({ renderLegacyChunks: false })],","handlingStrategy":"validation","validationCode":"function assertLegacyEntryWillExist(opts: { renderLegacyChunks?: boolean }, customPlugins: any[]) {\n  const genLegacy = opts.renderLegacyChunks !== false\n  const stripsLegacy = customPlugins.some(p => /delete b\\[k\\]|includes\\('-legacy'\\)/.test(String(p)) )\n  if (genLegacy && stripsLegacy) {\n    throw new Error('A custom plugin strips -legacy chunks - legacy entry will be missing')\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vite.build(cfg)\n} catch (e) {\n  if (e instanceof Error && /No corresponding legacy entry chunk/.test(e.message)) {\n    // either stop stripping -legacy chunks, or set renderLegacyChunks: false\n  } else throw e\n}","preventionTips":["Never delete output chunks whose name includes '-legacy'.","If legacy generation is undesired, set renderLegacyChunks: false rather than stripping output."],"tags":["plugin-legacy","transform-index-html","systemjs","build","legacy"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}