{"id":"779e46ab20e863dc","repo":"vitejs/vite","slug":"no-corresponding-legacy-polyfill-chunk-found-for","errorCode":null,"errorMessage":"No corresponding legacy polyfill chunk found for ${htmlFilename}","messagePattern":"No corresponding legacy polyfill chunk found for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugin-legacy/src/index.ts","lineNumber":820,"sourceCode":"        chunk.facadeModuleId,\n      )\n      if (legacyPolyfillFilename) {\n        tags.push({\n          tag: 'script',\n          attrs: {\n            nomodule: genModern,\n            crossorigin: true,\n            id: legacyPolyfillId,\n            src: toAssetPathFromHtml(\n              legacyPolyfillFilename,\n              chunk.facadeModuleId!,\n              config,\n            ),\n          },\n          injectTo: 'body',\n        })\n      } else if (legacyPolyfills.size) {\n        throw new Error(\n          `No corresponding legacy polyfill chunk found for ${htmlFilename}`,\n        )\n      }\n\n      // 5. inject legacy entry\n      const legacyEntryFilename = facadeToLegacyChunkMap.get(\n        chunk.facadeModuleId,\n      )\n      if (legacyEntryFilename) {\n        // `assets/foo.js` means importing \"named register\" in SystemJS\n        tags.push({\n          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.","sourceCodeStart":802,"sourceCodeEnd":838,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/plugin-legacy/src/index.ts#L802-L838","documentation":"Thrown in transformIndexHtml when legacy polyfills were collected (legacyPolyfills.size > 0) but no legacy polyfill chunk was registered for the current HTML entry. Analogous to the modern polyfill error (index 5) but for the legacy polyfill set. The facadeToLegacyPolyfillMap should have been populated during buildPolyfillChunk in generateBundle, but the entry's facadeModuleId has no corresponding entry.","triggerScenarios":"Same as the modern polyfill variant but for legacy polyfills: auto-detected or explicitly configured legacy polyfills exist, but the facadeModuleId of the HTML entry chunk doesn't match any chunk iterated in buildPolyfillChunk's bundle scan. Common with custom entry resolution or virtual HTML entry modules.","commonSituations":"Multi-page apps, custom plugins modifying entry module IDs, or MPA configs where HTML files are resolved through custom logic. Also seen when externalSystemJS is misconfigured alongside polyfill options.","solutions":["If polyfills is set to true (default auto-detect), try explicitly listing them: polyfills: ['es.array.flat', 'es.promise'].","Ensure rollupOptions.input HTML entries resolve to actual file paths that match facadeModuleId.","Check that no other plugin strips or rewrites facadeModuleId on entry chunks.","Update plugin-legacy to the latest version."],"exampleFix":"// before\nlegacy() // auto-detect polyfills, fails on unusual entries\n// after\nlegacy({ polyfills: ['es.array.flat', 'es.promise', 'regenerator-runtime'] })","handlingStrategy":"validation","validationCode":"// Pre-validate polyfill configuration for multi-page setups\nfunction validatePolyfillConfig(options, input) {\n  if (options.polyfills === true || options.polyfills === undefined) {\n    // auto-detect mode — ensure entries are standard HTML files\n    const entries = typeof input === 'object' ? Object.values(input) : [input]\n    for (const e of entries) {\n      if (!String(e).endsWith('.html')) {\n        console.warn(`Auto polyfill detection may fail for non-HTML entry: ${e}`)\n      }\n    }\n  }\n}","typeGuard":"function hasExplicitLegacyPolyfills(options: Options): boolean {\n  return Array.isArray(options.polyfills)\n}","tryCatchPattern":"try {\n  await build({\n    plugins: [legacy({ polyfills: ['es.promise', 'es.array.flat'] })]\n  })\n} catch (e) {\n  if (e.message.includes('No corresponding legacy polyfill chunk')) {\n    console.error('Switch to explicit polyfills array or check entry resolution')\n  }\n  throw e\n}","preventionTips":["Use explicit polyfills arrays for multi-page or complex entry setups.","Verify that no custom plugin rewrites entry facadeModuleId values.","Check externalSystemJS setting doesn't conflict with polyfill generation."],"tags":["plugin-legacy","polyfills","html","legacy"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}