{"id":"15e85c39acce792f","repo":"vitejs/vite","slug":"no-corresponding-modern-polyfill-chunk-found-for","errorCode":null,"errorMessage":"No corresponding modern polyfill chunk found for ${htmlFilename}","messagePattern":"No corresponding modern polyfill chunk found for (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/plugin-legacy/src/index.ts","lineNumber":765,"sourceCode":"        const modernPolyfillFilename = facadeToModernPolyfillMap.get(\n          chunk.facadeModuleId,\n        )\n\n        if (modernPolyfillFilename) {\n          tags.push({\n            tag: 'script',\n            attrs: {\n              type: 'module',\n              crossorigin: true,\n              src: toAssetPathFromHtml(\n                modernPolyfillFilename,\n                chunk.facadeModuleId!,\n                config,\n              ),\n            },\n          })\n        } else if (modernPolyfills.size) {\n          throw new Error(\n            `No corresponding modern polyfill chunk found for ${htmlFilename}`,\n          )\n        }\n      }\n\n      if (!genLegacy) {\n        return { html, tags }\n      }\n\n      // 2. inject importmaps\n      if (config.build.chunkImportMap) {\n        const importMap = facadeToLegacyImportMap.get(chunk.facadeModuleId)!\n        const decoder = new TextDecoder()\n        tags.push({\n          tag: 'script',\n          attrs: { type: 'systemjs-importmap' },\n          children:\n            typeof importMap.source === 'string'","sourceCodeStart":747,"sourceCodeEnd":783,"githubUrl":"https://github.com/vitejs/vite/blob/89620f09afcfef6b35e7bb8660132ab5b4d0cd3b/packages/plugin-legacy/src/index.ts#L747-L783","documentation":"Thrown in transformIndexHtml when modern polyfills were detected (modernPolyfills.size > 0) but no modern polyfill chunk was associated with the current HTML entry's facadeModuleId. The plugin expects that if polyfills are collected, the buildPolyfillChunk call in generateBundle created a chunk and registered it in facadeToModernPolyfillMap. A missing entry means the polyfill chunk wasn't built or the facadeModuleId didn't match any chunk in the bundle during registration.","triggerScenarios":"Multi-page apps where HTML entry files have unusual facadeModuleId values (e.g., virtual modules, custom resolveId). Also triggered when modernPolyfills is set to true (auto-detect) and polyfills are found, but the entry chunk's facadeModuleId is null or doesn't match what was registered during buildPolyfillChunk's bundle iteration.","commonSituations":"Using custom HTML entry resolution, multi-page setups with rollupOptions.input containing HTML files, or plugins that intercept entry module IDs. Can also happen when MPA input keys don't align with facadeModuleId after transformation.","solutions":["If you explicitly set modernPolyfills to true, try switching to an explicit array (e.g., modernPolyfills: ['es.array.flat']) to control which polyfills are included.","Check that your rollupOptions.input HTML entries resolve to stable, real file paths (not virtual IDs).","Update plugin-legacy; facadeModuleId matching has had fixes in newer versions.","If using a custom plugin that alters entry resolution, ensure it preserves the original facadeModuleId."],"exampleFix":"// before\nlegacy({ modernPolyfills: true })\n// after — explicit list avoids auto-detection facade mismatches\nlegacy({ modernPolyfills: [\n  'es.array.flat', 'es.promise', 'es.object.from-entries'\n] })","handlingStrategy":"validation","validationCode":"// Pre-validate that HTML entries have stable facadeModuleId values\nfunction validateHtmlEntries(input) {\n  const entries = typeof input === 'object' ? Object.values(input) : [input]\n  for (const entry of entries) {\n    if (typeof entry !== 'string' || !entry.endsWith('.html')) {\n      console.warn(`Input ${entry} may not resolve to a stable HTML facadeModuleId`)\n    }\n  }\n}\nvalidateHtmlEntries(config.build.rollupOptions.input)","typeGuard":"function hasExplicitModernPolyfills(options: Options): boolean {\n  return Array.isArray(options.modernPolyfills)\n}\n\n// prefer explicit to avoid auto-detection facade issues\nif (!hasExplicitModernPolyfills(opts)) {\n  console.warn('Consider setting modernPolyfills to an explicit array for multi-page apps')\n}","tryCatchPattern":"try {\n  await build({ plugins: [legacy({ modernPolyfills: explicitList })] })\n} catch (e) {\n  if (e.message.includes('No corresponding modern polyfill chunk')) {\n    console.error('Polyfill/entry facade mismatch. Try explicit modernPolyfills array.')\n  }\n  throw e\n}","preventionTips":["For multi-page apps, use explicit modernPolyfills arrays instead of auto-detection (true).","Ensure rollupOptions.input HTML files resolve to real file system paths.","Test each HTML entry independently to isolate which one triggers the mismatch."],"tags":["plugin-legacy","polyfills","html","multi-page"],"analyzedSha":"89620f09afcfef6b35e7bb8660132ab5b4d0cd3b","analyzedAt":"2026-08-03T19:28:02.920Z","schemaVersion":2}