{"record":{"id":"4d9640d21e41fc53","repo":"swc-project/swc","slug":"the-requested-const-module-module-name-does-no","errorCode":null,"errorMessage":"The requested const_module `{module_name}` does not provide an export named `{imported_name:?}`","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":199,"sourceCode":"                {\n                    let imported_name: Wtf8Atom = match prop {\n                        MemberProp::Ident(ref id) => id.sym.clone().into(),\n                        MemberProp::Computed(ref p) => match &*p.expr {\n                            Expr::Lit(Lit::Str(s)) => s.value.clone(),\n                            _ => return,\n                        },\n                        MemberProp::PrivateName(..) => return,\n                        #[cfg(swc_ast_unknown)]\n                        _ => panic!(\"unable to access unknown nodes\"),\n                    };\n\n                    let module_name_wtf8: Wtf8Atom = module_name.clone().into();\n                    let value = self\n                        .globals\n                        .get(&module_name_wtf8)\n                        .and_then(|entry| entry.get(&imported_name))\n                        .unwrap_or_else(|| {\n                            panic!(\n                                \"The requested const_module `{module_name}` does not provide an \\\n                                 export named `{imported_name:?}`\"\n                            )\n                        });\n\n                    *n = (**value).clone();\n                } else {\n                    n.visit_mut_children_with(self);\n                }\n            }\n            _ => {\n                n.visit_mut_children_with(self);\n            }\n        };\n    }\n\n    fn visit_mut_prop(&mut self, n: &mut Prop) {\n        match n {","sourceCodeStart":181,"sourceCodeEnd":217,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_optimization/src/const_modules.rs#L181-L217","documentation":"For a member access `NS.member` where NS is an imported const-module namespace, the transform looks up member's name (identifier or string prop) in the globals map for that module. A missing key panics with 'The requested const_module `{module_name}` does not provide an export named `{imported_name:?}`'.","triggerScenarios":"`import * as env from 'env'; env.MISSING` where the globals map for 'env' has no key named MISSING; also computed string props that do not match any key.","commonSituations":"Accessing a flag that was never added to globals, renaming members in source without updating .swcrc, dynamic member names from refactors, case mismatches between import usage and globals keys.","solutions":["Add the missing member key to that module's globals map","Change the access to an existing key (check exact spelling/casing)","Keep a single source of truth (TS types or JSON) for the const-module surface and validate imports against it"],"exampleFix":"// before\nimport * as env from '@app/env';\nif (env.DEV) enable();\n// globals: { \"@app/env\": { \"MODE\": \"'dev'\" } }\n\n// after\n// globals: { \"@app/env\": { \"MODE\": \"'dev'\", \"DEV\": \"true\" } }\nimport * as env from '@app/env';\nif (env.DEV) enable();","handlingStrategy":"validation","validationCode":"// JS: verify every NS.member access has a globals entry\nfunction checkMemberAccess(src, globals) {\n  const re = /import\\s*\\*\\s*as\\s+([\\w$]+)\\s+from\\s+['\"]([^'\"]+)['\"]/g;\n  for (const [, local, mod] of src.matchAll(re)) {\n    const known = Object.keys(globals[mod] ?? {});\n    const member = new RegExp(`${local}\\\\.([A-Za-z_$][\\\\w$]*)`, 'g');\n    for (const [, name] of src.matchAll(member)) {\n      if (!known.includes(name))\n        throw new Error(`const module \"${mod}\" does not export \"${name}\"`);\n    }\n  }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Maintain the const-module surface as typed constants shared with the SWC config","Run the member-access check in CI before transforms execute","Double-check spelling and casing when adding new member accesses"],"tags":["const-modules","member-access","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-14T00:17:10.932Z"}