{"record":{"id":"d0f237f7780eeea1","repo":"angular/angular-cli","slug":"failed-to-find-chunk-chunkid-in-set-n-json","errorCode":null,"errorMessage":"Failed to find chunk (${chunkId}) in set:\\n${JSON.stringify(chunks)}","messagePattern":"Failed to find chunk \\((.+?)\\) in set:\\\\n(.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/angular_devkit/build_angular/src/tools/webpack/utils/async-chunks.ts","lineNumber":38,"sourceCode":"  extraEntryPoints: NormalizedEntryPoint[],\n): StatsChunk[] {\n  const { chunks = [], entrypoints: entryPoints = {} } = webpackStats;\n\n  // Find all Webpack chunk IDs not injected into the main bundle. We don't have\n  // to worry about transitive dependencies because extra entry points cannot be\n  // depended upon in Webpack, thus any extra entry point with `inject: false`,\n  // **cannot** be loaded in main bundle.\n  const asyncChunkIds = extraEntryPoints\n    .filter((entryPoint) => !entryPoint.inject && entryPoints[entryPoint.bundleName])\n    .flatMap((entryPoint) =>\n      entryPoints[entryPoint.bundleName].chunks?.filter((n) => n !== 'runtime'),\n    );\n\n  // Find chunks for each ID.\n  const asyncChunks = asyncChunkIds.map((chunkId) => {\n    const chunk = chunks.find((chunk) => chunk.id === chunkId);\n    if (!chunk) {\n      throw new Error(`Failed to find chunk (${chunkId}) in set:\\n${JSON.stringify(chunks)}`);\n    }\n\n    return chunk;\n  });\n\n  // A chunk is considered `initial` only if Webpack already belives it to be initial\n  // and the application developer did not mark it async via an extra entry point.\n  return chunks.map((chunk) => {\n    return asyncChunks.find((asyncChunk) => asyncChunk === chunk)\n      ? {\n          ...chunk,\n          initial: false,\n        }\n      : chunk;\n  });\n}\n","sourceCodeStart":20,"sourceCodeEnd":55,"githubUrl":"https://github.com/angular/angular-cli/blob/bb72145f9ab45aee29f523236b3a25cd0813a841/packages/angular_devkit/build_angular/src/tools/webpack/utils/async-chunks.ts#L20-L55","documentation":"markAsyncChunksNonInitial maps a list of async chunk IDs back to webpack Chunk objects. When an ID in asyncChunkIds has no matching chunk in the compilation's chunk set, it cannot determine initial/lazy status and throws, dumping the chunk set for diagnosis. This indicates the chunk ID list and the compilation chunks are out of sync.","triggerScenarios":"Calling webpackStats (via markAsyncChunksNonInitial) when the stats/compilation contains async chunk IDs (e.g. from lazy-loaded modules or missing chunk merged states) that do not correspond to any chunk in the `chunks` collection — typically after chunk graph inconsistencies in webpack.","commonSituations":"Stale webpack cache after upgrading webpack or the CLI; corrupted .angular/cache; builds with aggressive chunk-splitting configs (splitChunks) that rename/remove chunks; webpack internal bugs with concatenated modules.","solutions":["Delete the .angular/cache directory and rebuild to clear stale chunk data.","Remove stale node_modules/.cache and dist folders, then rebuild.","Simplify/adjust `optimization.splitChunks` config that may be splitting async chunks unexpectedly.","Update Angular CLI and webpack to compatible versions (known chunk-graph bugs were fixed upstream)."],"exampleFix":"// before\nnpx ng build --configuration production\n// after\nrm -rf .angular/cache dist && npx ng build --configuration production","handlingStrategy":"try-catch","validationCode":"const missing = asyncChunkIds.filter(id => !chunks.some(c => c.id === id));\nif (missing.length) throw new Error(`Chunks missing from compilation: ${missing.join(', ')}`);","typeGuard":"function allChunksPresent(ids: (string|number)[], chunks: { id?: string|number }[]): boolean {\n  const known = new Set(chunks.map(c => c.id));\n  return ids.every(id => known.has(id));\n}","tryCatchPattern":"try {\n  const stats = webpackStatsLogger(...);\n} catch (err) {\n  if (err instanceof Error && err.message.startsWith('Failed to find chunk')) {\n    logger.warn('Chunk graph inconsistent; clearing webpack cache and retrying build.');\n    await rebuildWithoutCache();\n  } else throw err;\n}","preventionTips":["Clear .angular/cache when upgrading webpack or the CLI.","Avoid exotic splitChunks configs on async chunks without testing stats output.","Pin compatible angular-cli/webpack versions.","Delete dist and cache artifacts in CI before release builds."],"tags":["webpack","chunks","build-internal"],"backgroundTag":"chunk-not-found","analyzedSha":"bb72145f9ab45aee29f523236b3a25cd0813a841","analyzedAt":"2026-08-30T02:47:34.745Z","schemaVersion":2},"datasetVersion":"2026-08-30T03:17:51.788Z"}