swc-project/swc · error
prettier failed
Error message
prettier failed
What it means
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.
Source
Thrown at crates/dbg-swc/src/util/mod.rs:42
op()
}
pub fn gzipped_size(code: &str) -> usize {
let mut e = ZlibEncoder::new(Vec::new(), Compression::new(9));
e.write_all(code.as_bytes()).unwrap();
let compressed_bytes = e.finish().unwrap();
compressed_bytes.len()
}
pub fn make_pretty(f: &Path) -> Result<()> {
let mut c = Command::new("npx");
c.stderr(Stdio::inherit());
c.arg("js-beautify").arg("--replace").arg(f);
let output = c.output().context("failed to run prettier")?;
if !output.status.success() {
bail!("prettier failed");
}
Ok(())
}
pub fn parse_js(fm: Arc<SourceFile>) -> Result<ModuleRecord> {
let unresolved_mark = Mark::new();
let top_level_mark = Mark::new();
let mut errors = Vec::new();
let comments = SingleThreadedComments::default();
let res = parse_file_as_module(
&fm,
Syntax::Es(Default::default()),
EsVersion::latest(),
Some(&comments),
&mut errors,
)View on GitHub (pinned to 5176682b65)
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
Example fix
# before - message says prettier, tool is js-beautify $ npm install -g prettier # does not fix it error: prettier failed # after $ npm install -g js-beautify $ npx js-beautify --version 1.15.1
Defensive patterns
Strategy: validation
Validate before calling
use std::process::Command;
fn js_beautify_available() -> bool {
Command::new("npx")
.args(["js-beautify", "--version"])
.output()
.map(|o| o.status.success())
.unwrap_or(false)
}
// the message says 'prettier' but the tool invoked is js-beautify
assert!(js_beautify_available(), "install js-beautify: npm i -g js-beautify"); Try / catch
match make_pretty(&path) {
Ok(()) => {}
Err(e) if format!("{e:#}").contains("prettier failed") => {
// cosmetic formatting only - continue without pretty-printing
eprintln!("warning: js-beautify unavailable, skipping formatting: {e:#}");
}
Err(e) => return Err(e),
} Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- failed to run terser
- `deno bundle` failed with status code {}
- `npm run build` failed
- failed to run esbuild
- No `.js` or `.jsx` files found in `{}`
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/f096bd8f490c2d9d.
Report an issue: GitHub.