{"record":{"id":"241667571b9b76c1","repo":"swc-project/swc","slug":"the-requested-const-module-does-not-provide","errorCode":null,"errorMessage":"The requested const_module `{:?}` does not provide an export named `{:?}`","messagePattern":"The requested const_module `(.+?)` does not provide an export named `(.+?)`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_optimization/src/const_modules.rs","lineNumber":117,"sourceCode":"        *n = n.take().move_flat_map(|item| match item {\n            ModuleItem::ModuleDecl(ModuleDecl::Import(import)) => {\n                let entry = self.globals.get(&import.src.value);\n                if let Some(entry) = entry {\n                    for s in &import.specifiers {\n                        match *s {\n                            ImportSpecifier::Named(ref s) => {\n                                let imported = s\n                                    .imported\n                                    .as_ref()\n                                    .map(|m| match m {\n                                        ModuleExportName::Ident(id) => id.sym.clone().into(),\n                                        ModuleExportName::Str(s) => s.value.clone(),\n                                        #[cfg(swc_ast_unknown)]\n                                        _ => panic!(\"unable to access unknown nodes\"),\n                                    })\n                                    .unwrap_or_else(|| s.local.sym.clone().into());\n                                let value = entry.get(&imported).cloned().unwrap_or_else(|| {\n                                    panic!(\n                                        \"The requested const_module `{:?}` does not provide an \\\n                                         export named `{:?}`\",\n                                        import.src.value, imported\n                                    )\n                                });\n                                self.scope.imported.insert(imported.clone(), value);\n                            }\n                            ImportSpecifier::Namespace(ref s) => {\n                                self.scope.namespace.insert(s.local.to_id());\n                            }\n                            ImportSpecifier::Default(ref s) => {\n                                let imported: Wtf8Atom = s.local.sym.clone().into();\n                                let default_import_key: Wtf8Atom = atom!(\"default\").into();\n                                let value =\n                                    entry.get(&default_import_key).cloned().unwrap_or_else(|| {\n                                        panic!(\n                                            \"The requested const_module `{:?}` does not provide \\\n                                             default export\",","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_optimization/src/const_modules.rs#L99-L135","documentation":"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}`'.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before\nimport { API_URL } from '@app/env';\n// globals: { \"@app/env\": { \"FEATURE_FLAG\": \"true\" } }\n\n// after\n// globals: { \"@app/env\": { \"FEATURE_FLAG\": \"true\", \"API_URL\": \"'https://api.example'\" } }\nimport { API_URL } from '@app/env';","handlingStrategy":"validation","validationCode":"// JS: verify named imports against the globals map before transforming\nfunction checkNamedImports(src, globals) {\n  const re = /import\\s*\\{([^}]+)\\}\\s*from\\s*['\"]([^'\"]+)['\"]/g;\n  for (const [, names, mod] of src.matchAll(re)) {\n    const known = Object.keys(globals[mod] ?? {});\n    for (const n of names.split(',')) {\n      const name = n.trim().split(/\\s+as\\s+/)[0].replace(/['\"]/g, '');\n      if (name && !known.includes(name))\n        throw new Error(`const module \"${mod}\" does not export \"${name}\"`);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["const-modules","import","missing-export","globals"],"backgroundTag":"missing-module-export","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}