vitejs/vite · error · Error

No corresponding legacy entry chunk found for

Error message

No corresponding legacy entry chunk found for ${htmlFilename}

What it means

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.

Solutions

  1. Verify `dist/assets` contains a `-legacy.js` entry for each HTML entry.
  2. Remove plugins that manipulate `chunk.fileName` or skip chunks named with `-legacy`.
  3. 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`).
  4. Upgrade @vitejs/plugin-legacy and vite together to compatible versions.

Example fix

// before: a custom plugin deletes the legacy chunk
rollupOptions: { plugins: [ { name:'strip-legacy', generateBundle(_,b){ for(const k in b) if(k.includes('-legacy')) delete b[k] } } ] },
plugins: [legacy()],
// after: don't strip legacy chunks, or disable legacy generation explicitly
plugins: [legacy({ renderLegacyChunks: false })],
Defensive patterns

Strategy: validation

Validate before calling

function assertLegacyEntryWillExist(opts: { renderLegacyChunks?: boolean }, customPlugins: any[]) {
  const genLegacy = opts.renderLegacyChunks !== false
  const stripsLegacy = customPlugins.some(p => /delete b\[k\]|includes\('-legacy'\)/.test(String(p)) )
  if (genLegacy && stripsLegacy) {
    throw new Error('A custom plugin strips -legacy chunks - legacy entry will be missing')
  }
}

Try / catch

try {
  await vite.build(cfg)
} catch (e) {
  if (e instanceof Error && /No corresponding legacy entry chunk/.test(e.message)) {
    // either stop stripping -legacy chunks, or set renderLegacyChunks: false
  } else throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of vitejs/vite@b4d66fee14 (2026-08-11). Data as JSON: /api/errors/d03ff8403c9c79ea. Report an issue: GitHub.

Appendix: source

Thrown at packages/plugin-legacy/src/index.ts:850

          tag: 'script',
          attrs: {
            nomodule: genModern,
            crossorigin: true,
            // we set the entry path on the element as an attribute so that the
            // script content will stay consistent - which allows using a constant
            // hash value for CSP.
            id: legacyEntryId,
            'data-src': toAssetPathFromHtml(
              legacyEntryFilename,
              chunk.facadeModuleId!,
              config,
            ),
          },
          children: systemJSInlineCode,
          injectTo: 'body',
        })
      } else {
        throw new Error(
          `No corresponding legacy entry chunk found for ${htmlFilename}`,
        )
      }

      // 6. inject dynamic import fallback entry
      if (legacyPolyfillFilename && legacyEntryFilename && genModern) {
        tags.push({
          tag: 'script',
          attrs: { type: 'module' },
          children: detectModernBrowserCode,
          injectTo: 'head',
        })
        tags.push({
          tag: 'script',
          attrs: { type: 'module' },
          children: dynamicFallbackInlineCode,
          injectTo: 'head',
        })

View on GitHub (pinned to b4d66fee14)