swc-project/swc · error

Input is empty

Error message

Input is empty

What it means

swc CLI input collection: no positional files/directories were given, and stdin yielded no piped data, so collect_inputs has nothing to compile and bails with 'Input is empty' (crates/swc_cli_impl/src/commands/compile.rs). The stdin branch only activates when actual data is piped in.

Source

Thrown at crates/swc_cli_impl/src/commands/compile.rs:681

                    FileName::Anon.into()
                } else {
                    FileName::Real(options.filename.clone().into()).into()
                },
                stdin_input,
            );

            return Ok(vec![InputContext {
                options,
                fm,
                compiler,
                file_path: self
                    .filename
                    .clone()
                    .unwrap_or_else(|| PathBuf::from("unknown")),
            }]);
        }

        bail!("Input is empty");
    }

    fn transform_path(
        &self,
        compiler: Arc<Compiler>,
        file_path: &Path,
    ) -> anyhow::Result<TransformOutput> {
        let options = self.build_transform_options(&Some(file_path))?;
        let fm = compiler
            .cm
            .load_file(file_path)
            .context(format!("Failed to open file {}", file_path.display()))?;

        execute_transform(compiler, fm, options)
    }

    fn emit_output_dir_entry(
        &self,

View on GitHub (pinned to 5176682b65)

Solutions

  1. Pass explicit files or a directory: `swc ./src -d dist`
  2. Or pipe source through stdin: `cat input.js | swc`
  3. Audit scripts for empty variables/globs used as swc arguments

Example fix

# before (empty variable)
swc $FILES -d dist
# after
swc ${FILES:-./src} -d dist
Defensive patterns

Strategy: validation

Validate before calling

// JavaScript - verify there is real input before spawning swc
import fs from 'node:fs';
function hasCompileInput(files) {
  if (files.length > 0) return true;
  try { return !fs.stdin.isTTY && fs.statSync('/dev/stdin').size > 0; } catch { return false; }
}
if (!hasCompileInput(files)) {
  console.error('nothing to compile: pass files/dirs or pipe stdin');
  process.exit(1);
}

Prevention

When it happens

Trigger: Running bare `swc` in a non-TTY context where stdin is empty or closed (CI steps, containers); `swc -o out.js < /dev/null`; scripts invoking swc with an empty path variable.

Common situations: CI pipelines calling swc without arguments; watch wrappers; variable expansion producing zero file args; redirected-empty stdin in scripts.

Related errors


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/a9aed699e22892ae. Report an issue: GitHub.