{"record":{"id":"fc7d0e5d7cffdc66","repo":"swc-project/swc","slug":"the-requested-const-module-does-not-provide-fc7d0e","errorCode":null,"errorMessage":"The requested const_module `{:?}` does not provide default export","messagePattern":"The requested const_module `(.+?)` does not provide default export","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_optimization/src/const_modules.rs","lineNumber":133,"sourceCode":"                                    .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\",\n                                            import.src.value\n                                        )\n                                    });\n                                self.scope.imported.insert(imported, value);\n                            }\n                            #[cfg(swc_ast_unknown)]\n                            _ => panic!(\"unable to access unknown nodes\"),\n                        };\n                    }\n\n                    None\n                } else {\n                    Some(import.into())\n                }\n            }\n            _ => Some(item),","sourceCodeStart":115,"sourceCodeEnd":151,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_optimization/src/const_modules.rs#L115-L151","documentation":"For `import DefaultName from 'mod'` where 'mod' is a const module, the transform looks up the literal key \"default\" in that module's globals map. If no \"default\" entry exists it panics with 'The requested const_module `{src}` does not provide default export'.","triggerScenarios":"Default-importing a const module (import cfg from 'config') whose globals map defines only named keys and no \"default\" key.","commonSituations":"Adding a default import to code while the globals config was written for named imports only; assuming the first entry or the module name acts as the default value.","solutions":["Add a \"default\" entry to the module's globals map with the replacement expression","Switch the code to a named import that already has a globals entry","Remove the default import if unintended"],"exampleFix":"// before\nimport env from '@app/env';\n// globals: { \"@app/env\": { \"MODE\": \"'dev'\" } }\n\n// after\n// globals: { \"@app/env\": { \"default\": \"'dev'\", \"MODE\": \"'dev'\" } }\nimport env from '@app/env';","handlingStrategy":"validation","validationCode":"// JS: every module receiving a default import needs a \"default\" entry\nfunction checkDefaultImports(src, globals) {\n  const re = /import\\s+([\\w$]+)\\s+from\\s+['\"]([^'\"]+)['\"]/g;\n  for (const [, , mod] of src.matchAll(re)) {\n    if (globals[mod] && !('default' in globals[mod]))\n      throw new Error(`const module \"${mod}\" needs a \"default\" entry for default imports`);\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add a \"default\" entry whenever a const module may be default-imported","Prefer named imports for const modules to keep the contract explicit","Include default-import coverage in fixture tests for const modules"],"tags":["const-modules","default-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"}