{"record":{"id":"870bae42270345b8","repo":"swc-project/swc","slug":"node-path-provider-does-not-support-using-a-870bae","errorCode":null,"errorMessage":"Node path provider does not support using `{:?}` as a base file name","messagePattern":"Node path provider does not support using `(.+?)` as a base file name","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_module/src/path.rs","lineNumber":330,"sourceCode":"            }\n        };\n        let mut base = match base {\n            FileName::Real(v) => Cow::Borrowed(\n                v.parent()\n                    .ok_or_else(|| anyhow!(\"failed to get parent of {v:?}\"))?,\n            ),\n            FileName::Anon => match &self.config.base_dir {\n                Some(v) => Cow::Borrowed(&**v),\n                None => {\n                    if cfg!(target_arch = \"wasm32\") {\n                        panic!(\"Please specify `filename`\")\n                    } else {\n                        Cow::Owned(current_dir().expect(\"failed to get current directory\"))\n                    }\n                }\n            },\n            _ => {\n                unreachable!(\n                    \"Node path provider does not support using `{:?}` as a base file name\",\n                    base\n                )\n            }\n        };\n\n        if base.is_absolute() != target.is_absolute() {\n            if base.is_absolute() {\n                base = Cow::Owned(base.to_path_buf().clean());\n            } else {\n                base = Cow::Owned(absolute_base_path(self.config.base_dir.as_deref(), &base)?);\n            }\n\n            if target.is_absolute() {\n                target = target.clean();\n            } else {\n                target = absolute_path(self.config.base_dir.as_deref(), &target)?;\n            }","sourceCodeStart":312,"sourceCodeEnd":348,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_module/src/path.rs#L312-L348","documentation":"In the same NodePathProvider::try_resolve_import, the base (the importing file) must be FileName::Real (use its parent dir) or FileName::Anon (fall back to config base_dir / cwd). Any other FileName variant used as the base — Custom, Url, Internal — reaches the unreachable! because the provider cannot derive a directory to relativize from.","triggerScenarios":"Enabling module transforms (jsc.transform.modules / import rewriting) on a compile whose input file was registered as FileName::Custom(\"...\") or FileName::Url(..) instead of a real path or Anon — common in embedders that name virtual files with custom strings.","commonSituations":"Plugins compiling in-memory/virtual files but still expecting module resolution to work; wasm builds without a filename (the Anon arm additionally panics with `Please specify filename` unless base_dir/filename is set); tools copying swc configs between node and wasm environments.","solutions":["Register virtual input files as FileName::Anon and set config.base_dir, or supply a real path via FileName::Real so a parent directory exists.","For purely virtual pipelines, resolve imports yourself and disable specifier rewriting for those entries.","Update swc_ecma_transforms_module in case newer builds accept Custom bases.","Wrap the module transform in catch_unwind at your FFI boundary and fall back to unrewritten specifiers."],"exampleFix":"// before: virtual file named with Custom breaks relativization\n.cm.new_source_file(FileName::Custom(\"virtual/main.js\".into()), src);\n\n// after: use Anon + base_dir so the provider can resolve relatives\n.cm.new_source_file(FileName::Anon, src);\n// config.module_config.base_dir = Some(PathBuf::from(\"/project/virtual\"));","handlingStrategy":"validation","validationCode":"use swc_common::FileName;\nfn usable_base(f: &FileName) -> bool { matches!(f, FileName::Real(_) | FileName::Anon) }\n// before enabling jsc.transform.modules:\n// assert!(usable_base(&input_filename), \"base must be Real or Anon (set base_dir for Anon)\");","typeGuard":"fn is_supported_base(f: &FileName) -> bool { matches!(f, FileName::Real(_) | FileName::Anon) }","tryCatchPattern":null,"preventionTips":["Register in-memory files as FileName::Anon and configure base_dir instead of Custom names.","On wasm, always pass `filename` (the Anon path panics otherwise).","Run a smoke compile with module transform enabled for every new input source type."],"tags":["swc","transforms-module","path-resolution","filename","base-dir","virtual-files","panic"],"backgroundTag":"unsupported-filename-type","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}