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

  1. cd into the app directory and run 'npm run build' manually; fix whatever it reports first
  2. Run 'npm install' in the app before invoking the harness
  3. Confirm 'NEXT_DEBUG_MINIFY=1 npm run build' prints '{ name:' lines on stdout with your Next version
  4. 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

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


AI-assisted analysis of swc-project/swc@5176682b65 (2026-08-17). Data as JSON: /api/errors/d5b7628bcc381f73. Report an issue: GitHub.