{"record":{"id":"86ec3d459f824d42","repo":"swc-project/swc","slug":"failed-to-run-terser","errorCode":null,"errorMessage":"failed to run terser","messagePattern":"failed to run terser","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbg-swc/src/util/minifier.rs","lineNumber":93,"sourceCode":"    wrap_task(|| {\n        let mut cmd = Command::new(\"npx\");\n        cmd.arg(\"terser\");\n        cmd.stderr(Stdio::inherit());\n\n        if compress {\n            cmd.arg(\"--compress\");\n        }\n        if mangle {\n            cmd.arg(\"--mangle\");\n        }\n        cmd.args([\"--comments\", \"false\"]);\n        cmd.arg(\"--\");\n        cmd.arg(file);\n\n        let output = cmd.output().context(\"failed to get output\")?;\n\n        if !output.status.success() {\n            bail!(\"failed to run terser\");\n        }\n\n        let output = String::from_utf8(output.stdout).context(\"terser emitted non-utf8 string\")?;\n\n        // Drop comments\n        let cm = Arc::new(SourceMap::default());\n        let fm = cm.new_source_file(FileName::Anon.into(), output);\n        let m = parse_js(fm)?;\n\n        let code = print_js(cm, &m.module, true)?;\n\n        Ok(code)\n    })\n    .with_context(|| format!(\"failed to get output of {} from terser\", file.display()))\n}\n\npub fn get_esbuild_output(file: &Path, mangle: bool) -> Result<String> {\n    wrap_task(|| {","sourceCodeStart":75,"sourceCodeEnd":111,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/dbg-swc/src/util/minifier.rs#L75-L111","documentation":"dbg-swc's terser comparison spawns 'npx terser <file> [--compress] [--mangle] --comments false' with stderr inherited and requires a zero exit; a non-zero terser exit aborts with this message. The underlying terser error is already visible on stderr above it. Typical causes: terser not resolvable by npx (offline, missing install) or terser itself failing to parse the input JS.","triggerScenarios":"Running dbg-swc minifier comparison commands on a machine where 'npx terser' fails: package not installed and registry unreachable, npm auth/proxy issues, or a terser parse error on the candidate file (common during creduce mutation).","commonSituations":"Fresh CI containers without terser pre-installed; air-gapped environments where npx cannot fetch; mutated/invalid JS from test-case reduction that terser rejects before SWC comparison completes.","solutions":["Run 'npx terser --version' in the same shell; install terser (npm i -g terser or as a devDependency) if it is missing","Reproduce manually with the exact args: npx terser <file> --compress --mangle --comments false --","Ensure registry access for npx or pre-install so npx resolves from node_modules","If terser crashed on valid input, upgrade terser and re-run"],"exampleFix":"# before\n$ dbg-swc es minifier ...   # terser not installed\nerror: failed to run terser\n\n# after\n$ npm install -g terser\n$ npx terser --version\n5.31.0\n$ dbg-swc es minifier ...","handlingStrategy":"validation","validationCode":"use std::process::Command;\n\nfn terser_available() -> bool {\n    Command::new(\"npx\")\n        .args([\"terser\", \"--version\"])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}\n\n// gate comparison runs on tool availability\nassert!(terser_available(), \"install terser: npm i -g terser\");","typeGuard":null,"tryCatchPattern":"match get_terser_output(&file, compress, mangle) {\n    Ok(out) => out,\n    Err(e) if format!(\"{e:#}\").contains(\"failed to run terser\") => {\n        eprintln!(\"skipping terser diff: {e:#}\");\n        swc_output.clone() // degrade to swc-only comparison\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Pre-install terser (global or devDependency) in every environment running dbg-swc comparisons","Check 'npx terser --version' in CI setup steps","Run offline or proxy npm environments with a local node_modules so npx never fetches"],"tags":["dbg-swc","terser","npx","subprocess"],"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-14T05:17:10.506Z"}