{"record":{"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.environments.client.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/b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab/packages/plugin-legacy/src/index.ts#L747-L783","documentation":"During `transformIndexHtml`, if `genModern` is true and `modernPolyfills.size > 0` but `facadeToModernPolyfillMap.get(chunk.facadeModuleId)` is undefined for an HTML entry, plugin-legacy cannot find the generated modern-polyfill chunk that should be injected as `<script type=module>`. This indicates the polyfill chunk was expected (polyfills were configured/discovered) but was never recorded for that HTML facade, usually because `renderChunk` did not run the polyfill discovery for that output.","triggerScenarios":"Configuring `modernPolyfills` (or relying on automatic discovery) and building with multiple HTML entries or a custom `renderChunk`/output configuration where the modern polyfill bundle is not produced for a particular entry. Also seen when `renderModernChunks` is true but the modern polyfill set is populated yet the chunk map stays empty (e.g., manual bundle manipulation).","commonSituations":"Multi-page apps where one HTML entry lacks a corresponding modern polyfill chunk. Customizing rollup output in a way that skips the legacy plugin's `renderChunk`. Inconsistent plugin versions between vite and plugin-legacy.","solutions":["Ensure every HTML entry goes through the standard build pipeline so `renderChunk` populates `facadeToModernPolyfillMap`.","If you set `modernPolyfills` explicitly, verify the polyfill chunk is actually emitted (check `dist/assets` for the polyfill file).","Avoid custom `output`/manual chunking that strips or renames the polyfill chunk away from the plugin's discovery.","Upgrade @vitejs/plugin-legacy and vite to matching supported versions."],"exampleFix":"// before: modernPolyfills set but a custom output config drops the polyfill chunk\nbuild: {\n  rollupOptions: { output: { /* aggressive manualChunks that excludes polyfills */ } },\n},\nplugins: [legacy({ modernPolyfills: true })],\n// after: let plugin-legacy own the polyfill chunk, remove manual chunk overrides\nplugins: [legacy({ modernPolyfills: true })],","handlingStrategy":"validation","validationCode":"// Pre-build sanity: ensure modernPolyfills config is self-consistent\nfunction checkModernPolyfillsConfig(opts: { renderModernChunks?: boolean; modernPolyfills?: unknown }) {\n  const genModern = opts.renderModernChunks !== false\n  const hasPolyfills = Array.isArray(opts.modernPolyfills) ? opts.modernPolyfills.length > 0 : opts.modernPolyfills === true\n  if (!genModern && hasPolyfills) {\n    throw new Error('modernPolyfills set but renderModernChunks is false - polyfill chunk will be missing')\n  }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await vite.build(cfg)\n} catch (e) {\n  if (e instanceof Error && /No corresponding modern polyfill chunk/.test(e.message)) {\n    // remove custom rollup output overrides & rebuild, or drop modernPolyfills\n  } else throw e\n}","preventionTips":["Do not override rollupOptions.output in a way that renames/drops the polyfill chunk.","Keep vite and @vitejs/plugin-legacy versions in sync."],"tags":["plugin-legacy","polyfills","transform-index-html","build","multi-page"],"backgroundTag":null,"analyzedSha":"b4d66fee14d970f45b8a6f3d7d6aee73ca9b88ab","analyzedAt":"2026-08-11T11:49:19.515Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}