swc-project/swc · error
The requested const_module `{:?}` does not provide an export
Error message
The requested const_module `{:?}` does not provide an export named `{:?}` What it means
When input code does `import { X } from 'mod'` and 'mod' is registered as a const module, the transform replaces X with the value stored under key X in the globals map for that module. If the key is absent it panics with 'The requested const_module `{src}` does not provide an export named `{name}`'.
Source
Thrown at crates/swc_ecma_transforms_optimization/src/const_modules.rs:117
*n = n.take().move_flat_map(|item| match item {
ModuleItem::ModuleDecl(ModuleDecl::Import(import)) => {
let entry = self.globals.get(&import.src.value);
if let Some(entry) = entry {
for s in &import.specifiers {
match *s {
ImportSpecifier::Named(ref s) => {
let imported = s
.imported
.as_ref()
.map(|m| match m {
ModuleExportName::Ident(id) => id.sym.clone().into(),
ModuleExportName::Str(s) => s.value.clone(),
#[cfg(swc_ast_unknown)]
_ => panic!("unable to access unknown nodes"),
})
.unwrap_or_else(|| s.local.sym.clone().into());
let value = entry.get(&imported).cloned().unwrap_or_else(|| {
panic!(
"The requested const_module `{:?}` does not provide an \
export named `{:?}`",
import.src.value, imported
)
});
self.scope.imported.insert(imported.clone(), value);
}
ImportSpecifier::Namespace(ref s) => {
self.scope.namespace.insert(s.local.to_id());
}
ImportSpecifier::Default(ref s) => {
let imported: Wtf8Atom = s.local.sym.clone().into();
let default_import_key: Wtf8Atom = atom!("default").into();
let value =
entry.get(&default_import_key).cloned().unwrap_or_else(|| {
panic!(
"The requested const_module `{:?}` does not provide \
default export",View on GitHub (pinned to 5176682b65)
Solutions
- Add the missing export name to the globals map for that module (e.g. "API_URL": "'https://api.example'"
- Fix the import specifier to match an existing key exactly, including casing and string vs identifier names
- Remove the import if the constant is no longer needed
Example fix
// before
import { API_URL } from '@app/env';
// globals: { "@app/env": { "FEATURE_FLAG": "true" } }
// after
// globals: { "@app/env": { "FEATURE_FLAG": "true", "API_URL": "'https://api.example'" } }
import { API_URL } from '@app/env'; Defensive patterns
Strategy: validation
Validate before calling
// JS: verify named imports against the globals map before transforming
function checkNamedImports(src, globals) {
const re = /import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g;
for (const [, names, mod] of src.matchAll(re)) {
const known = Object.keys(globals[mod] ?? {});
for (const n of names.split(',')) {
const name = n.trim().split(/\s+as\s+/)[0].replace(/['"]/g, '');
if (name && !known.includes(name))
throw new Error(`const module "${mod}" does not export "${name}"`);
}
}
} Prevention
- Keep globals maps and imported names in one typed source of truth
- Add a lint/CI step comparing const-module imports to config keys
- Watch for casing and string-name mismatches when copying import names
When it happens
Trigger: A named import whose local/imported name (including string ModuleExportName) has no matching key in the globals map for that module; typos, casing mistakes, or entries removed during config refactors.
Common situations: Importing constants like import { API_URL } from 'config' while globals only defines other keys; renaming exports in source without updating the .swcrc globals; string-name exports (import { 'x' as y }) mismatching the map.
Related errors
- The requested const_module `{:?}` does not provide default e
- The requested const_module `{module_name}` does not provide
- failed to parse jsx option {}: '{}' is not an expression
- The const_module namespace `{sym}` cannot be used without me
- The const_module namespace `{}` cannot be used without membe
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/241667571b9b76c1.
Report an issue: GitHub.