{"record":{"id":"e177b6d490058600","repo":"swc-project/swc","slug":"strip-leading-paths-requires-out-dir","errorCode":null,"errorMessage":"--strip-leading-paths requires --out-dir","messagePattern":"--strip-leading-paths requires --out-dir","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_cli_impl/src/commands/compile.rs","lineNumber":521,"sourceCode":"\n        Ok(options)\n    }\n\n    fn validate(&self) -> anyhow::Result<()> {\n        if self.watch && self.out_file.is_none() && self.out_dir.is_none() {\n            bail!(\"--watch requires --out-file or --out-dir\");\n        }\n\n        if self.watch && self.files.is_empty() {\n            bail!(\"--watch requires input files\");\n        }\n\n        if self.copy_files && self.out_dir.is_none() {\n            bail!(\"--copy-files requires --out-dir\");\n        }\n\n        if self.strip_leading_paths && self.out_dir.is_none() {\n            bail!(\"--strip-leading-paths requires --out-dir\");\n        }\n\n        Ok(())\n    }\n\n    fn included_extensions(&self) -> Vec<String> {\n        self.extensions.clone().unwrap_or_else(|| {\n            DEFAULT_EXTENSIONS\n                .iter()\n                .map(|value| value.to_string())\n                .collect()\n        })\n    }\n\n    fn has_directory_input(&self) -> bool {\n        self.files.iter().any(|path| path.is_dir())\n    }\n","sourceCodeStart":503,"sourceCodeEnd":539,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_cli_impl/src/commands/compile.rs#L503-L539","documentation":"swc CLI validation: --strip-leading-paths removes leading path segments (like ./src) from output file paths, which only makes sense when writing a directory tree. Without --out-dir the flag has no effect target, so validate() rejects the combination.","triggerScenarios":"Running `swc --strip-leading-paths input.js` or any invocation with the flag but no -d/--out-dir.","commonSituations":"Flags carried over from directory-mode commands into single-file mode; deleting the -d flag during debugging while leaving dependent flags.","solutions":["Add --out-dir: `swc ./src -d dist --strip-leading-paths`","Or remove the flag if compiling without an output directory"],"exampleFix":"# before\nswc --strip-leading-paths ./src\n# after\nswc ./src -d dist --strip-leading-paths","handlingStrategy":"validation","validationCode":"if (argv['strip-leading-paths'] && !argv['out-dir']) {\n  throw new Error('--strip-leading-paths requires --out-dir');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only use --strip-leading-paths with an output directory tree","When trimming flags while debugging, re-run swc --help to recheck coupled options"],"tags":["swc-cli","strip-leading-paths","cli-options","validation"],"backgroundTag":"missing-required-cli-option","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"}