{"record":{"id":"6d35e474e177b034","repo":"swc-project/swc","slug":"watch-requires-input-files","errorCode":null,"errorMessage":"--watch requires input files","messagePattern":"--watch requires input files","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_cli_impl/src/commands/compile.rs","lineNumber":513,"sourceCode":"                \"true\" => SourceMapsConfig::Bool(true),\n                value => SourceMapsConfig::Str(value.to_string()),\n            });\n\n            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())","sourceCodeStart":495,"sourceCodeEnd":531,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_cli_impl/src/commands/compile.rs#L495-L531","documentation":"The SWC CLI's validate() rejects a --watch invocation that names no input files: watch mode needs at least one entry in `files` to know what to compile and re-compile on change. Raised via bail! before any compilation starts, so nothing is processed.","triggerScenarios":"Running `swc -w -d dist` with no positional inputs; a variable intended to hold paths expanding to nothing in an npm script.","commonSituations":"CI/scripts where the file list variable is empty; assuming watch uses a .swcrc-declared entry (it does not - entries come from CLI args).","solutions":["Provide the paths to watch: `swc -w ./src -d dist`","Check scripts for unquoted/empty variables passed to swc"],"exampleFix":"# before\nswc --watch -d dist\n# after\nswc --watch ./src -d dist","handlingStrategy":"validation","validationCode":"# Shell - enforce watch input precondition\nif [[ \"$WATCH\" == \"1\" && ${#INPUTS[@]} -eq 0 ]]; then\n  echo \"--watch requires input files\" >&2; exit 1;\nfi","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Check that path variables/globs expand to at least one entry before watch runs","Remember swc watch never reads stdin; entries come from CLI args"],"tags":["swc-cli","watch","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"}