swc-project/swc · error

The requested const_module `{module_name}` does not provide

Error message

The requested const_module `{module_name}` does not provide an export named `{imported_name:?}`

What it means

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:?}`'.

Source

Thrown at crates/swc_ecma_transforms_optimization/src/const_modules.rs:199

                {
                    let imported_name: Wtf8Atom = match prop {
                        MemberProp::Ident(ref id) => id.sym.clone().into(),
                        MemberProp::Computed(ref p) => match &*p.expr {
                            Expr::Lit(Lit::Str(s)) => s.value.clone(),
                            _ => return,
                        },
                        MemberProp::PrivateName(..) => return,
                        #[cfg(swc_ast_unknown)]
                        _ => panic!("unable to access unknown nodes"),
                    };

                    let module_name_wtf8: Wtf8Atom = module_name.clone().into();
                    let value = self
                        .globals
                        .get(&module_name_wtf8)
                        .and_then(|entry| entry.get(&imported_name))
                        .unwrap_or_else(|| {
                            panic!(
                                "The requested const_module `{module_name}` does not provide an \
                                 export named `{imported_name:?}`"
                            )
                        });

                    *n = (**value).clone();
                } else {
                    n.visit_mut_children_with(self);
                }
            }
            _ => {
                n.visit_mut_children_with(self);
            }
        };
    }

    fn visit_mut_prop(&mut self, n: &mut Prop) {
        match n {

View on GitHub (pinned to 5176682b65)

Solutions

  1. Add the missing member key to that module's globals map
  2. Change the access to an existing key (check exact spelling/casing)
  3. Keep a single source of truth (TS types or JSON) for the const-module surface and validate imports against it

Example fix

// before
import * as env from '@app/env';
if (env.DEV) enable();
// globals: { "@app/env": { "MODE": "'dev'" } }

// after
// globals: { "@app/env": { "MODE": "'dev'", "DEV": "true" } }
import * as env from '@app/env';
if (env.DEV) enable();
Defensive patterns

Strategy: validation

Validate before calling

// JS: verify every NS.member access has a globals entry
function checkMemberAccess(src, globals) {
  const re = /import\s*\*\s*as\s+([\w$]+)\s+from\s+['"]([^'"]+)['"]/g;
  for (const [, local, mod] of src.matchAll(re)) {
    const known = Object.keys(globals[mod] ?? {});
    const member = new RegExp(`${local}\\.([A-Za-z_$][\\w$]*)`, 'g');
    for (const [, name] of src.matchAll(member)) {
      if (!known.includes(name))
        throw new Error(`const module "${mod}" does not export "${name}"`);
    }
  }
}

Prevention

When it happens

Trigger: `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.

Common situations: 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.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/4d9640d21e41fc53. Report an issue: GitHub.