{"record":{"id":"a9aed699e22892ae","repo":"swc-project/swc","slug":"input-is-empty","errorCode":null,"errorMessage":"Input is empty","messagePattern":"Input is empty","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/swc_cli_impl/src/commands/compile.rs","lineNumber":681,"sourceCode":"                    FileName::Anon.into()\n                } else {\n                    FileName::Real(options.filename.clone().into()).into()\n                },\n                stdin_input,\n            );\n\n            return Ok(vec![InputContext {\n                options,\n                fm,\n                compiler,\n                file_path: self\n                    .filename\n                    .clone()\n                    .unwrap_or_else(|| PathBuf::from(\"unknown\")),\n            }]);\n        }\n\n        bail!(\"Input is empty\");\n    }\n\n    fn transform_path(\n        &self,\n        compiler: Arc<Compiler>,\n        file_path: &Path,\n    ) -> anyhow::Result<TransformOutput> {\n        let options = self.build_transform_options(&Some(file_path))?;\n        let fm = compiler\n            .cm\n            .load_file(file_path)\n            .context(format!(\"Failed to open file {}\", file_path.display()))?;\n\n        execute_transform(compiler, fm, options)\n    }\n\n    fn emit_output_dir_entry(\n        &self,","sourceCodeStart":663,"sourceCodeEnd":699,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/swc_cli_impl/src/commands/compile.rs#L663-L699","documentation":"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.","triggerScenarios":"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.","commonSituations":"CI pipelines calling swc without arguments; watch wrappers; variable expansion producing zero file args; redirected-empty stdin in scripts.","solutions":["Pass explicit files or a directory: `swc ./src -d dist`","Or pipe source through stdin: `cat input.js | swc`","Audit scripts for empty variables/globs used as swc arguments"],"exampleFix":"# before (empty variable)\nswc $FILES -d dist\n# after\nswc ${FILES:-./src} -d dist","handlingStrategy":"validation","validationCode":"// JavaScript - verify there is real input before spawning swc\nimport fs from 'node:fs';\nfunction hasCompileInput(files) {\n  if (files.length > 0) return true;\n  try { return !fs.stdin.isTTY && fs.statSync('/dev/stdin').size > 0; } catch { return false; }\n}\nif (!hasCompileInput(files)) {\n  console.error('nothing to compile: pass files/dirs or pipe stdin');\n  process.exit(1);\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default file lists to a concrete directory (e.g. ./src) in scripts","In CI, assert arguments are non-empty before invoking swc","Pipe explicitly: `cat file.js | swc` when using stdin"],"tags":["swc-cli","stdin","input","validation"],"backgroundTag":"empty-stdin-input","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"}