swc-project/swc · error
determine_export_name({:?})
Error message
determine_export_name({:?}) What it means
The UMD transform derives the global export name from the module's file name. Only `FileName::Real` and `FileName::Custom` carry a name `global_name` can use; `Anon`, `Url`, `Internal`, `Macros` and other variants hit `unimplemented!("determine_export_name(...)")` because no identifier can be derived.
Source
Thrown at crates/swc_ecma_transforms_module/src/umd/config.rs:87
src.split('/').next_back().unwrap().to_camel_case().into()
}
pub fn determine_export_name(&self, filename: Lrc<FileName>) -> Ident {
match &*filename {
FileName::Real(ref path) => {
let s = match path.file_stem() {
Some(stem) => self.global_name(&stem.to_string_lossy()),
None => self.global_name(&path.display().to_string()),
};
quote_ident!(s).into()
}
FileName::Custom(s) => {
let s = self.global_name(s);
quote_ident!(s).into()
}
_ => unimplemented!("determine_export_name({:?})", filename),
}
}
}
View on GitHub (pinned to d7d7434666)
Solutions
- Create the source file with `FileName::Custom("myLib".into())` or a real path before running the UMD transform
- Prefer `FileName::Custom` for virtual modules so the derived global name is deterministic (camelCased from the string)
- If you use the high-level Compiler API, always pass a real `filename` in the compile options
Example fix
// before
let fm = cm.new_source_file(FileName::Anon.into(), code.to_string());
// after
let fm = cm.new_source_file(FileName::Custom("myLib".into()).into(), code.to_string()); Defensive patterns
Strategy: validation
Validate before calling
// Rust: guard the filename before running the UMD transform
fn usable_for_umd(f: &FileName) -> bool {
matches!(f, FileName::Real(_) | FileName::Custom(_))
}
assert!(usable_for_umd(&fm.name), "UMD requires a Real or Custom FileName"); Type guard
fn has_export_name_source(f: &FileName) -> bool {
matches!(f, FileName::Real(_) | FileName::Custom(_))
} Prevention
- Never build source files with `FileName::Anon` in pipelines that run module-format transforms
- Use `FileName::Custom("libName")` for virtual modules so the UMD global name is deterministic
When it happens
Trigger: Run the UMD pass on a module whose SourceMap file was created with `FileName::Anon` — the common default in tests and ad-hoc tools (`cm.new_source_file(FileName::Anon.into(), code)`) — or with Url/Internal names.
Common situations: Tests and one-off compilers that never set a real filename; pipelines feeding virtual modules; plugins creating source files with generated internal names.
Related errors
- derive(Merge) does not support an enum
- corejs version other than 2 / 3
- not implemented
- emitting decorator metadata while using new proposal
- Invalid path "{path:?}"
AI-assisted analysis of swc-project/swc@d7d7434666 (2026-08-16).
Data as JSON: /api/errors/48b8fdca8131767f.
Report an issue: GitHub.