{"record":{"id":"9bd1c50e015160cb","repo":"swc-project/swc","slug":"could-not-find-swcrc-file-while-using-rootmode-u","errorCode":null,"errorMessage":"Could not find .swcrc file while using rootMode \"upward\".\nSearched from: {}","messagePattern":"Could not find \\.swcrc file while using rootMode \"upward\"\\.\nSearched from: (.+?)","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc/src/lib.rs","lineNumber":754,"sourceCode":"\n            let root = root.as_ref().unwrap_or(&CUR_DIR);\n\n            let swcrc_path = match config_file {\n                Some(ConfigFile::Str(s)) => Some(PathBuf::from(s.clone())),\n                _ => {\n                    if *swcrc {\n                        if let FileName::Real(ref path) = name {\n                            // Canonicalize relative paths for proper parent traversal\n                            let abs_path = if path.is_relative() {\n                                root.join(path).canonicalize().ok()\n                            } else {\n                                path.canonicalize().ok()\n                            };\n                            let found = abs_path.and_then(|p| find_swcrc(&p, root, *root_mode));\n\n                            // \"upward\" mode requires a .swcrc to be found\n                            if found.is_none() && *root_mode == RootMode::Upward {\n                                bail!(\n                                    \"Could not find .swcrc file while using rootMode \\\n                                     \\\"upward\\\".\\nSearched from: {}\",\n                                    path.display()\n                                );\n                            }\n\n                            found\n                        } else {\n                            None\n                        }\n                    } else {\n                        None\n                    }\n                }\n            };\n\n            let config_file = match swcrc_path.as_deref() {\n                Some(s) => Some(load_swcrc(s)?),","sourceCodeStart":736,"sourceCodeEnd":772,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc/src/lib.rs#L736-L772","documentation":"With `rootMode: \"upward\"`, swc walks parent directories from the input file looking for a .swcrc and treats 'not found' as fatal, bailing with the search start path in the message (crates/swc/src/lib.rs). Other rootModes silently fall back to defaults, which is why this error is specific to upward mode.","triggerScenarios":"Compiling with swcrc: true and rootMode 'upward' where no .swcrc exists anywhere between the file's directory and the filesystem root - e.g. files outside the project (tmp dirs, generated scratch), or relative paths canonicalized against a wrong root/CWD.","commonSituations":"Monorepo tooling forcing rootMode upward while compiling files above the package root; running the compiler from a different working directory so upward traversal starts in the wrong place; .swcrc renamed or excluded from the deploy image.","solutions":["Create a .swcrc in the project root (or nearest directory covering all compiled files)","Or change rootMode to 'nearest'/'none' if falling back to defaults is acceptable","Verify the traversal start: run from the project directory and prefer absolute input paths"],"exampleFix":"# before\nswc --sync --config-file .swcrc ./src -d dist   # rootMode upward, no .swcrc above ./src\n# after\necho '{ \"jsc\": { \"parser\": { \"syntax\": \"typescript\" } } }' > .swcrc\nswc ./src -d dist","handlingStrategy":"validation","validationCode":"// JavaScript - replicate the upward search before running swc\nimport fs from 'node:fs';\nimport path from 'node:path';\nfunction findSwcrcUpward(startFile, root) {\n  let dir = path.resolve(root, path.dirname(startFile));\n  for (;;) {\n    const candidate = path.join(dir, '.swcrc');\n    if (fs.existsSync(candidate)) return candidate;\n    const parent = path.dirname(dir);\n    if (parent === dir) return null;\n    dir = parent;\n  }\n}\n// if (rootMode === 'upward' && !findSwcrcUpward(file, root)) throw new Error('no .swcrc upward');","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Commit a .swcrc at the repo root when using rootMode upward","Run compilers from the project directory with absolute input paths","Include .swcrc in Docker/CI images (don't gitignore or prune it)"],"tags":["swc","swcrc","root-mode","config-discovery"],"backgroundTag":"missing-config-file","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"}