{"record":{"id":"d8dc9f1382b5fa50","repo":"swc-project/swc","slug":"swcrc-exists-but-not-matched","errorCode":null,"errorMessage":".swcrc exists but not matched","messagePattern":"\\.swcrc exists but not matched","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc/src/config/mod.rs","lineNumber":1190,"sourceCode":"                None => return Ok(Some(c)),\n            },\n            Rc::Multi(cs) => cs,\n        };\n\n        match filename {\n            Some(filename) => {\n                for mut c in cs {\n                    if c.matches(filename)? {\n                        c.adjust(filename);\n\n                        return Ok(Some(c));\n                    }\n                }\n            }\n            None => return Ok(Some(Config::default())),\n        }\n\n        bail!(\".swcrc exists but not matched\")\n    }\n}\n\n/// A single object in the `.swcrc` file\n#[derive(Debug, Default, Clone, Deserialize, Merge)]\n#[serde(deny_unknown_fields, rename_all = \"camelCase\")]\npub struct Config {\n    #[serde(default)]\n    pub env: Option<swc_ecma_preset_env::Config>,\n\n    #[serde(default)]\n    pub test: Option<FileMatcher>,\n\n    #[serde(default)]\n    pub exclude: Option<FileMatcher>,\n\n    #[serde(default)]\n    pub jsc: JscConfig,","sourceCodeStart":1172,"sourceCodeEnd":1208,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc/src/config/mod.rs#L1172-L1208","documentation":"Raised by `Rc::into_config` when a .swcrc was found and loaded, a filename was supplied, but no config object in the file matches that filename. Each config entry matches via its `test` and `exclude` fields (regex/pattern `FileMatcher`); the loop falls through and swc bails. It means 'configuration exists on disk, but none of its entries claim this file'.","triggerScenarios":"A .swcrc whose entries all use `test` regexes like \"\\.tsx?$\" while the compiled file is `.js`; an `exclude` pattern matching the path so the entry is skipped; multiple entries where the catch-all entry was removed. Hit via swc CLI compile or Compiler::process_js_file with a real file path.","commonSituations":"Adding plain .js files to a TypeScript-only .swcrc; exclude patterns broader than intended; regexes written for forward slashes failing on Windows paths; renaming file extensions (mjs/cjs/jsx) not covered by `test`.","solutions":["Add or fix a config entry whose `test` covers the failing extension, e.g. \"test\": \"\\\\.m?js$\"","Check `exclude` on every entry - an entry may match `test` but be knocked out by `exclude`, causing fall-through","Test the regex against the exact path form swc sees (absolute path, separators, case)","Pass --config-file explicitly if a different/unexpected .swcrc is being loaded"],"exampleFix":"// before (.swcrc)\n[\n  { \"test\": \"\\\\.tsx?$\", \"jsc\": { \"parser\": { \"syntax\": \"typescript\" } } }\n]\n// after (.swcrc)\n[\n  { \"test\": \"\\\\.tsx?$\", \"jsc\": { \"parser\": { \"syntax\": \"typescript\" } } },\n  { \"test\": \"\\\\.m?js$\", \"jsc\": { \"parser\": { \"syntax\": \"ecmascript\" } } }\n]","handlingStrategy":"validation","validationCode":"// JavaScript - verify a .swcrc entry claims the file before compiling\nimport fs from 'node:fs';\nfunction configMatchesFile(swcrcPath, filePath) {\n  const configs = JSON.parse(fs.readFileSync(swcrcPath, 'utf8'));\n  const list = Array.isArray(configs) ? configs : [configs];\n  return list.some((c) => {\n    const test = c.test ? new RegExp(c.test) : null;\n    const excl = c.exclude ? new RegExp(c.exclude) : null;\n    return (!test || test.test(filePath)) && !(excl && excl.test(filePath));\n  });\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Keep a catch-all entry (no `test`) last in multi-entry .swcrc files","Cover every extension you compile: ts, tsx, js, jsx, mjs, cjs","Test `test`/`exclude` regexes against absolute paths, including Windows separators"],"tags":["swc","swcrc","config","file-matching","regex"],"backgroundTag":"config-file-not-matched","analyzedSha":"5176682b65416c6b5de6b47379ae1588ea3ecb3f","analyzedAt":"2026-08-17T16:16:52.067Z","contentChangedAt":"2026-08-17T16:16:52.067Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}