swc-project/swc · error
--watch requires input files
Error message
--watch requires input files
What it means
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.
Source
Thrown at crates/swc_cli_impl/src/commands/compile.rs:513
"true" => SourceMapsConfig::Bool(true),
value => SourceMapsConfig::Str(value.to_string()),
});
self.source_file_name
.clone_into(&mut options.source_file_name);
self.source_root.clone_into(&mut options.source_root);
}
Ok(options)
}
fn validate(&self) -> anyhow::Result<()> {
if self.watch && self.out_file.is_none() && self.out_dir.is_none() {
bail!("--watch requires --out-file or --out-dir");
}
if self.watch && self.files.is_empty() {
bail!("--watch requires input files");
}
if self.copy_files && self.out_dir.is_none() {
bail!("--copy-files requires --out-dir");
}
if self.strip_leading_paths && self.out_dir.is_none() {
bail!("--strip-leading-paths requires --out-dir");
}
Ok(())
}
fn included_extensions(&self) -> Vec<String> {
self.extensions.clone().unwrap_or_else(|| {
DEFAULT_EXTENSIONS
.iter()
.map(|value| value.to_string())View on GitHub (pinned to 5176682b65)
Solutions
- Provide the paths to watch: `swc -w ./src -d dist`
- Check scripts for unquoted/empty variables passed to swc
Example fix
# before swc --watch -d dist # after swc --watch ./src -d dist
Defensive patterns
Strategy: validation
Validate before calling
# Shell - enforce watch input precondition
if [[ "$WATCH" == "1" && ${#INPUTS[@]} -eq 0 ]]; then
echo "--watch requires input files" >&2; exit 1;
fi Prevention
- 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
When it happens
Trigger: Running `swc -w -d dist` with no positional inputs; a variable intended to hold paths expanding to nothing in an npm script.
Common situations: CI/scripts where the file list variable is empty; assuming watch uses a .swcrc-declared entry (it does not - entries come from CLI args).
Related errors
- --watch requires --out-file or --out-dir
- --copy-files requires --out-dir
- --strip-leading-paths requires --out-dir
- Input is empty
- `{raw}` is not a valid ecmascript version
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/6d35e474e177b034.
Report an issue: GitHub.