{"record":{"id":"65d52405d19fc8a1","repo":"rolldown/rolldown","slug":"consumer-local-route-should-have-complete-namespac","errorCode":null,"errorMessage":"consumer-local route should have complete namespace targets","messagePattern":"consumer-local route should have complete namespace targets","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/rolldown/src/stages/generate_stage/compute_wrapped_esm_init_metadata.rs","lineNumber":284,"sourceCode":"            namespace: namespace_reexport_is_retained,\n          },\n        ) {\n          continue;\n        }\n        if stmt_is_included\n          && overlay.is_none_or(|overlay| overlay.retained_reexport_path.is_empty())\n        {\n          continue;\n        }\n      } else if !is_reexport {\n        continue;\n      }\n      let mut targets = vec![];\n      if namespace_reexport_is_retained && ctx.order_state.is_consumer_local_reexport_route(root) {\n        let namespace_targets = ctx\n          .order_state\n          .consumer_local_namespace_targets(root)\n          .expect(\"consumer-local route should have complete namespace targets\");\n        targets.extend(namespace_targets.iter().copied().filter(|target| match target {\n          WrappedEsmInitTarget::Module(module_idx) => {\n            ctx.order_state.esm_init_included_in_live_chunk(\n              &ctx.metas[*module_idx],\n              *module_idx,\n              ctx.chunk_graph,\n            )\n          }\n          WrappedEsmInitTarget::CjsCarrier(key) => {\n            ctx.order_state.order_cjs_carrier_included_in_live_chunk(*key, ctx.chunk_graph)\n          }\n        }));\n      } else if ctx.order_wrap {\n        // A recorded retained path restricts the hop walk to the chains resolved reads consumed.\n        // That is only sound when the path is the record's whole evidence: an included namespace\n        // (or forwarded dynamic exports) retains EVERY non-ambiguous export of this star record —\n        // including chains no resolved read recorded — so the walk must stay unrestricted there or\n        // the off-path pure definers lose their only init call site.","sourceCodeStart":266,"sourceCodeEnd":302,"githubUrl":"https://github.com/rolldown/rolldown/blob/91b44b9d7bcfb5725533478e044e3891a251b2c5/crates/rolldown/src/stages/generate_stage/compute_wrapped_esm_init_metadata.rs#L266-L302","documentation":"This is an internal invariant panic in rolldown's chunk-generation phase. When a namespace re-export is retained on a consumer-local re-export route, the bundler expects its order-state bookkeeping to already hold the complete list of namespace init targets for that route; `consumer_local_namespace_targets` returning None means that bookkeeping was never populated, i.e. the bundler's wrapped-ESM init ordering logic violated its own contract.","triggerScenarios":"Hitting this requires the chunk graph to contain a consumer-local namespace re-export (`export * from` / namespace re-export of a module that stays within the same chunk group) that is retained in the output while the wrapped-ESM init metadata pass finds no namespace targets recorded for that route. It is reached through normal `Bundle`/`rollup` builds, not a user-facing API call, and almost always indicates a bundler bug triggered by an unusual module graph shape (circular namespace re-exports mixed with dynamic imports or code-splitting).","commonSituations":"Large codebases with circular `export * from` chains combined with dynamic imports/entry-level code splitting; upgrading rolldown versions where the consumer-local re-export route detection changed; rare graph shapes in monorepos with barrel files that re-export each other.","solutions":["Reduce the input to a minimal reproduction (barrel file with circular `export *` + dynamic import) and file an issue at https://github.com/rolldown/rolldown/issues with the repro and rolldown version","Try the latest rolldown version — this invariant is frequently fixed in patch releases","Restructure the offending barrel files to use explicit named re-exports instead of `export *` to sidestep the consumer-local re-export route","As a workaround, disable or adjust advanced chunking options (e.g. `experimental.strictExecutionOrder`, `advancedChunks`) that change wrapped-ESM init ordering","Check whether a specific plugin is generating the re-export graph and bypass/replace it"],"exampleFix":"// before (problematic module graph)\n// a.js: export * from './b.js'; export const a = 1;\n// b.js: export * from './a.js';\n// after\n// a.js: export { b } from './b.js'; export const a = 1;\n// b.js: export const b = 2;","handlingStrategy":"validation","validationCode":"// Pre-build sanity check for circular namespace re-exports\nimport { globSync } from 'node:fs';\n// grep source for 'export *' chains; if a cycle exists, restructure before building\nfunction hasExportStarCycle(files) {\n  const seen = new Set();\n  const visit = (f) => {\n    if (seen.has(f)) return true; seen.add(f);\n    return (readExportStars(f) || []).some(visit);\n  };\n  return files.some(visit);\n}\nif (hasExportStarCycle(entryFiles)) console.warn('circular export * detected: may trip rolldown wrapped-esm init invariant');","typeGuard":"function isRolldownPanic(err) {\n  return err instanceof Error && /consumer-local route should have complete namespace targets/.test(err.message);\n}","tryCatchPattern":"try {\n  await bundle();\n} catch (err) {\n  if (/consumer-local route should have complete namespace targets/.test(String(err))) {\n    console.error('Rolldown internal invariant hit; report repro + version, or flatten export * chains');\n    process.exitCode = 1;\n  } else throw err;\n}","preventionTips":["Prefer explicit named re-exports over `export *` in barrel files","Avoid circular barrel-file graphs in monorepos","Pin and regularly update rolldown versions; read changelogs for wrapped-ESM fixes","Keep a minimal reproduction of the failing graph when reporting","Test code-splitting-heavy graphs in CI so regressions surface early"],"tags":["rust","internal-invariant","code-splitting","esm"],"backgroundTag":"internal-invariant-violation","analyzedSha":"91b44b9d7bcfb5725533478e044e3891a251b2c5","analyzedAt":"2026-09-07T16:04:13.504Z","contentChangedAt":"2026-09-07T16:04:13.504Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}