{"record":{"id":"9295ad446bf57226","repo":"swc-project/swc","slug":"failed-to-run-esbuild","errorCode":null,"errorMessage":"failed to run esbuild","messagePattern":"failed to run esbuild","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbg-swc/src/util/minifier.rs","lineNumber":126,"sourceCode":"}\n\npub fn get_esbuild_output(file: &Path, mangle: bool) -> Result<String> {\n    wrap_task(|| {\n        let mut cmd = Command::new(\"esbuild\");\n        cmd.stderr(Stdio::inherit());\n\n        cmd.arg(file);\n\n        if mangle {\n            cmd.arg(\"--minify\");\n        } else {\n            cmd.arg(\"--minify-syntax\").arg(\"--minify-whitespace\");\n        }\n\n        let output = cmd.output().context(\"failed to get output\")?;\n\n        if !output.status.success() {\n            bail!(\"failed to run esbuild\");\n        }\n\n        String::from_utf8(output.stdout).context(\"esbuild emitted non-utf8 string\")\n    })\n    .with_context(|| format!(\"failed to get output of {} from esbuild\", file.display()))\n}\n\n/// We target es5 while esbuild does not support it.\n///\n/// Due to the difference, reducer generates something useless\nstruct Normalizer {}\n\nimpl VisitMut for Normalizer {\n    noop_visit_mut_type!(fail);\n\n    fn visit_mut_prop(&mut self, p: &mut Prop) {\n        p.visit_mut_children_with(self);\n","sourceCodeStart":108,"sourceCodeEnd":144,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/dbg-swc/src/util/minifier.rs#L108-L144","documentation":"dbg-swc's esbuild comparison spawns the esbuild binary directly (Command::new('esbuild'), not via npx) with --minify / --minify-syntax --minify-whitespace, and requires a zero exit; non-zero aborts with this message while esbuild's stderr is already on your terminal. Unlike the terser path, this requires esbuild to be on PATH. Failures are a missing binary, or esbuild rejecting the input file.","triggerScenarios":"Running dbg-swc minifier comparison on a machine without esbuild on PATH (binary not found usually surfaces as the earlier 'failed to get output' context error, while a found-but-failing esbuild exits non-zero here), or esbuild failing to parse the candidate input.","commonSituations":"esbuild installed only as a project devDependency (node_modules/.bin not on PATH) while the harness expects a global binary; version drift where esbuild rejects syntax SWC emitted; CI images that install terser but not esbuild.","solutions":["Install esbuild globally (npm i -g esbuild) or ensure node_modules/.bin is on PATH","Verify with 'esbuild --version' in the same shell","Reproduce manually: esbuild <file> --minify-syntax --minify-whitespace","Upgrade esbuild if it rejects input SWC considers valid"],"exampleFix":"# before\n$ which esbuild   # empty - only a local devDependency\nerror: failed to run esbuild\n\n# after\n$ npm install -g esbuild\n$ esbuild --version\n0.23.0\n$ dbg-swc es minifier ...","handlingStrategy":"validation","validationCode":"use std::process::Command;\n\nfn esbuild_on_path() -> bool {\n    Command::new(\"esbuild\")\n        .arg(\"--version\")\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}\n\nassert!(esbuild_on_path(), \"install esbuild: npm i -g esbuild (must be on PATH, not just node_modules)\");","typeGuard":null,"tryCatchPattern":"match get_esbuild_output(&file, mangle) {\n    Ok(out) => out,\n    Err(e) if format!(\"{e:#}\").contains(\"failed to run esbuild\") => {\n        eprintln!(\"skipping esbuild diff: {e:#}\");\n        swc_output.clone()\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["This path spawns the esbuild binary directly - global install or PATH including node_modules/.bin is required","Verify 'esbuild --version' in the same shell that runs dbg-swc","Keep terser and esbuild installs in lockstep in CI images that run minifier comparisons"],"tags":["dbg-swc","esbuild","subprocess","path"],"backgroundTag":"external-tool-exit-nonzero","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"}