swc-project/swc · error
`npm run build` failed
Error message
`npm run build` failed
What it means
The minifier size-check harness runs 'npm run build' inside a cloned Next.js app (with FORCE_COLOR=3 and NEXT_DEBUG_MINIFY=1) and requires exit 0 before scraping stdout for debug lines; a non-zero build aborts here. stderr is inherited, so the real Next.js build errors are already printed to your terminal above this message. The failure is an app-build failure, not an SWC failure.
Source
Thrown at crates/dbg-swc/src/es/minifier/next/check_size.rs:202
info!("Running `npm run build`");
// Remove cache
let _ = remove_dir_all(app_dir.join(".next"));
let mut c = Command::new("npm");
c.current_dir(app_dir);
c.env("FORCE_COLOR", "3");
c.env("NEXT_DEBUG_MINIFY", "1");
c.arg("run").arg("build");
c.stderr(Stdio::inherit());
let output = c
.output()
.context("failed to get output of `npm run build`")?;
if !output.status.success() {
bail!("`npm run build` failed");
}
let output = String::from_utf8_lossy(&output.stdout);
output
.par_lines()
.filter(|line| line.contains("{ name:"))
.map(|line| {
parse_loose_json::<InputFile>(line).context("failed to parse input file")
})
.collect::<Result<_>>()
})
.with_context(|| format!("failed to build app in `{}`", app_dir.display()))
}
fn minify_file(&self, cm: Arc<SourceMap>, js_file: &Path) -> Result<CompareResult> {
wrap_task(|| {
let terser_full =View on GitHub (pinned to 5176682b65)
Solutions
- cd into the app directory and run 'npm run build' manually; fix whatever it reports first
- Run 'npm install' in the app before invoking the harness
- Confirm 'NEXT_DEBUG_MINIFY=1 npm run build' prints '{ name:' lines on stdout with your Next version
- Disable network-dependent steps (telemetry, fonts) in next.config when running in a sandbox
Example fix
# before $ dbg-swc es minifier next check-size ... # app deps never installed error: `npm run build` failed # after $ cd ./apps/next-app && npm install && npm run build # green $ cd - && dbg-swc es minifier next check-size ...
Defensive patterns
Strategy: validation
Validate before calling
#!/usr/bin/env bash
# prove the app builds before handing it to the size-check harness
cd "$APP_DIR" || exit 2
npm ci || exit 2
FORCE_COLOR=3 NEXT_DEBUG_MINIFY=1 npm run build > /tmp/next-build.log 2>&1 || {
echo 'npm run build failed - fix app errors first' >&2; exit 2;
}
grep -q '{ name:' /tmp/next-build.log || {
echo 'NEXT_DEBUG_MINIFY lines missing - Next version incompatible' >&2; exit 2;
}
# only now invoke dbg-swc es minifier next check-size Prevention
- Always run 'npm install' / 'npm ci' in the target app before the harness
- Pre-check that NEXT_DEBUG_MINIFY=1 produces '{ name:' lines with your Next.js version
- Keep the target app pinned (Node + Next versions) in CI for reproducible size runs
When it happens
Trigger: Running dbg-swc's next.js minifier size check against an app whose production build fails: missing node_modules, type errors, invalid next.config.js, or an incompatible Next.js version.
Common situations: Skipping 'npm install' in the target app before the harness; Node/Next version mismatches; sandboxed environments where telemetry or remote font fetching breaks the build; Next versions whose NEXT_DEBUG_MINIFY output format no longer matches what the harness parses.
Related errors
- `deno bundle` failed with status code {}
- We don't care about this file
- failed to run terser
- failed to run esbuild
- prettier failed
AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17).
Data as JSON: /api/errors/d5b7628bcc381f73.
Report an issue: GitHub.