{"record":{"id":"4fe16e14bb673894","repo":"swc-project/swc","slug":"copy-files-requires-out-dir","errorCode":null,"errorMessage":"--copy-files requires --out-dir","messagePattern":"--copy-files requires --out-dir","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_cli_impl/src/commands/compile.rs","lineNumber":517,"sourceCode":"            self.source_file_name\n                .clone_into(&mut options.source_file_name);\n            self.source_root.clone_into(&mut options.source_root);\n        }\n\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","sourceCodeStart":499,"sourceCodeEnd":535,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_cli_impl/src/commands/compile.rs#L499-L535","documentation":"swc CLI validation: --copy-files copies non-compilable assets (JSON, images, etc.) from the input tree into the output tree, which is only meaningful with a directory-shaped output. Without --out-dir, validate() rejects the flag.","triggerScenarios":"Running `swc --copy-files input.js` (single-file mode, no -d), where there is no output directory to copy assets into.","commonSituations":"Copying a command from a directory-mode example but running it on a single file; removing -d while iterating and forgetting the coupled flag.","solutions":["Add --out-dir: `swc ./src -d dist --copy-files`","Or drop --copy-files when compiling a single file to stdout"],"exampleFix":"# before\nswc --copy-files ./src\n# after\nswc ./src -d dist --copy-files","handlingStrategy":"validation","validationCode":"const needsOutDir = Boolean(argv['copy-files'] || argv['strip-leading-paths']);\nif (needsOutDir && !argv['out-dir']) {\n  throw new Error('--copy-files requires --out-dir');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Treat --copy-files and --strip-leading-paths as directory-mode-only flags","Keep directory-mode flags grouped with -d in shared command templates"],"tags":["swc-cli","copy-files","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-14T05:17:10.506Z"}