{"record":{"id":"d5b7628bcc381f73","repo":"swc-project/swc","slug":"npm-run-build-failed","errorCode":null,"errorMessage":"`npm run build` failed","messagePattern":"`npm run build` failed","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"crates/dbg-swc/src/es/minifier/next/check_size.rs","lineNumber":202,"sourceCode":"            info!(\"Running `npm run build`\");\n\n            // Remove cache\n            let _ = remove_dir_all(app_dir.join(\".next\"));\n\n            let mut c = Command::new(\"npm\");\n            c.current_dir(app_dir);\n            c.env(\"FORCE_COLOR\", \"3\");\n            c.env(\"NEXT_DEBUG_MINIFY\", \"1\");\n            c.arg(\"run\").arg(\"build\");\n\n            c.stderr(Stdio::inherit());\n\n            let output = c\n                .output()\n                .context(\"failed to get output of `npm run build`\")?;\n\n            if !output.status.success() {\n                bail!(\"`npm run build` failed\");\n            }\n\n            let output = String::from_utf8_lossy(&output.stdout);\n\n            output\n                .par_lines()\n                .filter(|line| line.contains(\"{ name:\"))\n                .map(|line| {\n                    parse_loose_json::<InputFile>(line).context(\"failed to parse input file\")\n                })\n                .collect::<Result<_>>()\n        })\n        .with_context(|| format!(\"failed to build app in `{}`\", app_dir.display()))\n    }\n\n    fn minify_file(&self, cm: Arc<SourceMap>, js_file: &Path) -> Result<CompareResult> {\n        wrap_task(|| {\n            let terser_full =","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/swc-project/swc/blob/5176682b65416c6b5de6b47379ae1588ea3ecb3f/crates/dbg-swc/src/es/minifier/next/check_size.rs#L184-L220","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"# before\n$ dbg-swc es minifier next check-size ...  # app deps never installed\nerror: `npm run build` failed\n\n# after\n$ cd ./apps/next-app && npm install && npm run build  # green\n$ cd - && dbg-swc es minifier next check-size ...","handlingStrategy":"validation","validationCode":"#!/usr/bin/env bash\n# prove the app builds before handing it to the size-check harness\ncd \"$APP_DIR\" || exit 2\nnpm ci || exit 2\nFORCE_COLOR=3 NEXT_DEBUG_MINIFY=1 npm run build > /tmp/next-build.log 2>&1 || {\n  echo 'npm run build failed - fix app errors first' >&2; exit 2;\n}\ngrep -q '{ name:' /tmp/next-build.log || {\n  echo 'NEXT_DEBUG_MINIFY lines missing - Next version incompatible' >&2; exit 2;\n}\n# only now invoke dbg-swc es minifier next check-size","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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"],"tags":["dbg-swc","nextjs","npm","subprocess","minifier"],"backgroundTag":"build-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"}