swc-project/swc · error
determine_export_name
Error message
determine_export_name({:?}) What it means
When building UMD output, swc_ecma_transforms_module derives the global/export identifier from the input FileName: real paths use the file stem, FileName::Custom uses the string directly. Every other FileName variant (anonymous stdin input, internal buffers, command-line pseudo files) has no defined mapping and panics with unimplemented!.
Solutions
- Give the input a real file name before transforming, e.g. FileName::Custom("index".into()) or a real PathBuf
- When using the swc crate's Compiler, pass the source through a named file or set the filename on the transform task instead of feeding an anonymous SourceFile
- Avoid `module.type = "umd"` for anonymous/eval-compiled inputs, or pre-map them to a custom name
Example fix
// before
let fm = cm.new_source_file(FileName::Anon.into(), src);
// after
let fm = cm.new_source_file(FileName::Custom("index".into()).into(), src); Defensive patterns
Strategy: validation
Validate before calling
// Rust: check the FileName variant before running the UMD transform
use swc_common::FileName;
fn umd_safe_filename(f: &FileName) -> bool {
matches!(f, FileName::Real(_) | FileName::Custom(_))
}
assert!(umd_safe_filename(&*source_file.name), "UMD transform requires a Real or Custom file name"); Prevention
- Always assign a concrete filename when creating SourceFiles for programmatic transforms (FileName::Custom as fallback)
- Never rely on FileName::Anon/stdin inputs when module.type is umd
- Add an integration test that transforms an in-memory string to catch anonymous-filename paths early
When it happens
Trigger: Running the UMD module transform on a source whose FileName is not Real or Custom — typically FileName::Anon created via SourceMap::anon / new_source_file with an anonymous name when transforming an in-memory string or stdin without setting a filename.
Common situations: Using the swc Compiler/API to transform an in-memory string or stdin buffer with jsc.parser/module UMD settings; test harnesses that build SourceFiles without names.
Related errors
- emitting decorator metadata while using new proposal
- `env` and `jsc.target` cannot be used together
- Error occurred while loading config file at
- failed to find input source map file
- failed to parse inline source map: not base64
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/48b8fdca8131767f.
Report an issue: GitHub.
Appendix: 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 5176682b65)