{"record":{"id":"f096bd8f490c2d9d","repo":"swc-project/swc","slug":"prettier-failed","errorCode":null,"errorMessage":"prettier failed","messagePattern":"prettier failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbg-swc/src/util/mod.rs","lineNumber":42,"sourceCode":"    op()\n}\n\npub fn gzipped_size(code: &str) -> usize {\n    let mut e = ZlibEncoder::new(Vec::new(), Compression::new(9));\n    e.write_all(code.as_bytes()).unwrap();\n    let compressed_bytes = e.finish().unwrap();\n    compressed_bytes.len()\n}\n\npub fn make_pretty(f: &Path) -> Result<()> {\n    let mut c = Command::new(\"npx\");\n    c.stderr(Stdio::inherit());\n    c.arg(\"js-beautify\").arg(\"--replace\").arg(f);\n\n    let output = c.output().context(\"failed to run prettier\")?;\n\n    if !output.status.success() {\n        bail!(\"prettier failed\");\n    }\n\n    Ok(())\n}\n\npub fn parse_js(fm: Arc<SourceFile>) -> Result<ModuleRecord> {\n    let unresolved_mark = Mark::new();\n    let top_level_mark = Mark::new();\n\n    let mut errors = Vec::new();\n    let comments = SingleThreadedComments::default();\n    let res = parse_file_as_module(\n        &fm,\n        Syntax::Es(Default::default()),\n        EsVersion::latest(),\n        Some(&comments),\n        &mut errors,\n    )","sourceCodeStart":24,"sourceCodeEnd":60,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/dbg-swc/src/util/mod.rs#L24-L60","documentation":"Despite the function name and the message saying 'prettier', make_pretty actually runs 'npx js-beautify --replace <file>' and bails when that exits non-zero; the name is historical. So the failing tool is js-beautify, not prettier. Common causes: npx cannot resolve or download js-beautify (offline, no install) or js-beautify rejects the file.","triggerScenarios":"dbg-swc code paths that format reduced/minimized test files invoke make_pretty on machines where 'npx js-beautify' fails to run: package missing and registry unreachable, or js-beautify exiting non-zero on the mutated file.","commonSituations":"Air-gapped CI where npx cannot fetch packages; developers installing prettier because the error message mentions it (wrong tool); files mangled by test reduction that js-beautify cannot reformat.","solutions":["Install the right tool: npm i -g js-beautify (the message says prettier but js-beautify is what runs)","Verify with 'npx js-beautify --version' in the same environment","Ensure network/registry access for npx or pre-install locally","If js-beautify fails on one specific file, inspect that file for encoding corruption first"],"exampleFix":"# before - message says prettier, tool is js-beautify\n$ npm install -g prettier   # does not fix it\nerror: prettier failed\n\n# after\n$ npm install -g js-beautify\n$ npx js-beautify --version\n1.15.1","handlingStrategy":"validation","validationCode":"use std::process::Command;\n\nfn js_beautify_available() -> bool {\n    Command::new(\"npx\")\n        .args([\"js-beautify\", \"--version\"])\n        .output()\n        .map(|o| o.status.success())\n        .unwrap_or(false)\n}\n\n// the message says 'prettier' but the tool invoked is js-beautify\nassert!(js_beautify_available(), \"install js-beautify: npm i -g js-beautify\");","typeGuard":null,"tryCatchPattern":"match make_pretty(&path) {\n    Ok(()) => {}\n    Err(e) if format!(\"{e:#}\").contains(\"prettier failed\") => {\n        // cosmetic formatting only - continue without pretty-printing\n        eprintln!(\"warning: js-beautify unavailable, skipping formatting: {e:#}\");\n    }\n    Err(e) => return Err(e),\n}","preventionTips":["Install js-beautify, not prettier - the error text names the wrong tool","Treat pretty-printing as optional in scripts so its failure never aborts a run","Ensure registry access for npx or keep js-beautify pre-installed in CI images"],"tags":["dbg-swc","js-beautify","npx","subprocess","formatter"],"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"}