{"record":{"id":"ccdd36e4369a26e8","repo":"swc-project/swc","slug":"cannot-specify-multiple-files-when-using-a-directo","errorCode":null,"errorMessage":"Cannot specify multiple files when using a directory as input","messagePattern":"Cannot specify multiple files when using a directory as input","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_cli_impl/src/commands/compile.rs","lineNumber":290,"sourceCode":"        .iter()\n        .filter_map(|path| absolutize_path(path).ok())\n        .collect()\n}\n\n/// Infer list of files from cli arguments.\n#[cfg_attr(debug_assertions, tracing::instrument(level = \"info\", skip_all))]\nfn collect_input_files(\n    raw_files_input: &[PathBuf],\n    ignore_pattern: Option<&Pattern>,\n    excluded_dir: Option<&Path>,\n) -> anyhow::Result<Vec<InputFile>> {\n    let input_dir = raw_files_input.iter().find(|path| path.is_dir());\n    let cwd = std::env::current_dir()?;\n    let excluded_dir = excluded_dir.map(absolutize_path).transpose()?;\n\n    let files = if let Some(input_dir) = input_dir {\n        if raw_files_input.len() > 1 {\n            bail!(\"Cannot specify multiple files when using a directory as input\");\n        }\n\n        WalkDir::new(input_dir)\n            .into_iter()\n            .filter_entry(|entry| {\n                // Avoid descending into generated output when --out-dir is\n                // nested inside the watched or compiled input tree.\n                !excluded_dir\n                    .as_deref()\n                    .map(|excluded_dir| is_same_or_nested_path(entry.path(), excluded_dir))\n                    .unwrap_or(false)\n            })\n            .filter_map(|entry| entry.ok())\n            .map(|entry| entry.into_path())\n            .filter(|path| path.is_file())\n            .filter(|path| !is_ignored_path(path, ignore_pattern, &cwd))\n            .map(|path| InputFile {\n                path,","sourceCodeStart":272,"sourceCodeEnd":308,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_cli_impl/src/commands/compile.rs#L272-L308","documentation":"swc CLI compile input collection (crates/swc_cli_impl/src/commands/compile.rs): if any positional input is a directory, it must be the only input. Mixing a directory with extra files is rejected up front because directory mode recursively collects all compilable files itself.","triggerScenarios":"Running `swc ./src extra.js` or `npx swc lib/ setup.js` - any invocation where one input path is a directory and raw_files_input.len() > 1.","commonSituations":"Shell scripts appending explicit files to a directory argument; glob expansion that includes a directory; copy-pasted commands mixing modes.","solutions":["Pass the directory alone; select extensions inside it with --extensions if needed","Or list the individual files explicitly without the directory"],"exampleFix":"# before\nswc ./src ./setup.js -d dist\n# after\nswc ./src -d dist","handlingStrategy":"validation","validationCode":"# Shell / JS - reject dir + file mixes before invoking swc\nconst hasDir = inputs.some((p) => fs.statSync(p).isDirectory());\nif (hasDir && inputs.length > 1) {\n  throw new Error('pass the directory alone, or only files');\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pick one input mode per invocation: a single directory OR explicit files","Use --extensions to scope directory collection instead of adding files alongside","Wrap swc in a script that validates argv shape"],"tags":["swc-cli","input","arguments","directory-input"],"backgroundTag":"invalid-cli-argument","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"}