swc-project/swc · error
module item found but is_es6 is false: {:?}
Error message
module item found but is_es6 is false: {:?} What it means
A consistency check panic while building the CommonJS wrapper function in the bundler's chunk output (cjs.rs:142). The generated wrapper's body is assembled from module items; the invariant is that items are only emitted into the CJS interop wrapper when the module is treated as ES6 (is_es6). If a module item is present but the is_es6 flag is false, module classification and item collection have diverged, and the panic fires to expose that internal inconsistency.
Source
Thrown at crates/swc_bundler/src/bundler/chunk/cjs.rs:142
pat: Pat::Ident(Ident::new(atom!("module"), DUMMY_SP, local_ctxt).into()),
},
// exports
Param {
span: DUMMY_SP,
decorators: Default::default(),
pat: Pat::Ident(Ident::new(atom!("exports"), DUMMY_SP, local_ctxt).into()),
},
],
decorators: Vec::new(),
span: DUMMY_SP,
body: Some(FunctionBody {
span: dep.span,
stmts: dep
.body
.into_iter()
.map(|v| match v {
ModuleItem::ModuleDecl(i) => {
unreachable!("module item found but is_es6 is false: {:?}", i)
}
ModuleItem::Stmt(s) => s,
#[cfg(swc_ast_unknown)]
_ => panic!("unable to access unknown nodes"),
})
.collect(),
}),
is_generator: false,
is_async: false,
..Default::default()
}),
}
.into();
// var load = __swcpack_require__.bind(void 0, moduleDecl)
VarDecl {
span: DUMMY_SP,View on GitHub (pinned to 5176682b65)
Solutions
- Log the offending module item and its module id to find which module was misclassified
- Ensure the module graph classification pass (which sets is_es6) runs before chunk item collection and uses the same criteria
- Skip non-ES6 items in the CJS wrapper construction instead of panicking if the item is genuinely irrelevant
Defensive patterns
Strategy: type-guard
When it happens
Trigger: Thrown at crates/swc_bundler/src/bundler/chunk/cjs.rs:142 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/b94201859c47d6f1.
Report an issue: GitHub.