{"record":{"id":"a427270ab3368cb7","repo":"swc-project/swc","slug":"please-specify-filename","errorCode":null,"errorMessage":"Please specify `filename`","messagePattern":"Please specify `filename`","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_ecma_transforms_module/src/path.rs","lineNumber":323,"sourceCode":"            FileName::Real(v) => v,\n            FileName::Custom(s) => return Ok(self.to_specifier(s.into(), slug)),\n            _ => {\n                unreachable!(\n                    \"Node path provider does not support using `{:?}` as a target file name\",\n                    target\n                )\n            }\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)?);","sourceCodeStart":305,"sourceCodeEnd":341,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_ecma_transforms_module/src/path.rs#L305-L341","documentation":"The node-modules path provider resolves specifiers relative to a base directory. When the input file is FileName::Anon and no config.base_dir is set, native builds fall back to current_dir(); on wasm32 there is no current directory, so the code panics with 'Please specify `filename`'.","triggerScenarios":"Running SWC compiled to wasm32 (browser, wasm bindings, plugins) with a transform that triggers node-style path resolution while the source has no real filename and base_dir is None.","commonSituations":"Wasm builds of SWC used in playgrounds or in-browser bundlers, calling process()/transform without a filename option, plugin configs that rely on cwd-relative resolution that works natively but not in wasm.","solutions":["Pass a real filename for the source being processed (e.g. filename: 'src/index.js' in transform options) so base resolution has an anchor","Set base_dir in the resolver/path-provider config to a known virtual root","Avoid node-modules resolution paths in wasm builds unless you provide both filename and base_dir"],"exampleFix":"// before\nimport { transformSync } from '@swc/core/wasm';\ntransformSync(code, {}); // FileName::Anon, no base_dir -> panic on wasm\n\n// after\ntransformSync(code, { filename: 'src/index.js' });","handlingStrategy":"validation","validationCode":"// JS (wasm build): always anchor transforms with a filename\nfunction safeTransform(code, opts) {\n  if (!opts.filename) throw new Error('filename is required for path resolution on wasm');\n  return transformSync(code, opts);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always pass a filename option in wasm/browser builds","Configure base_dir for the node path provider when using virtual file systems","Test path-dependent transforms in a wasm target as part of CI"],"tags":["wasm","filename","resolver","config","browser"],"backgroundTag":"missing-filename","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"}