Command "npm run build" exited with 1

Problem

next build fails without throwing any reasonable errors. Local build finishes successfully

Node: 20 / 22
NextJS: 15.1.6

Similar issues

Unlike this stackoverflow reference build script was always set to next build in ours project

What has been done already

Node version switch from 22 to 20 and vice versa
strict: false
typescript: { ignoreBuildErrors: true }
eslint: { ignoreDuringBuilds: true }

Deploy / Build Logs

[16:26:21.131] Running build in Washington, D.C., USA (East) – iad1
[16:26:21.268] Cloning <PROJECT_NAME> (Branch: develop, Commit: e256631)
[16:26:22.260] Previous build caches not available
[16:26:22.296] Cloning completed: 1.030s
[16:26:22.607] Running "vercel build"
[16:26:22.989] Vercel CLI 40.1.0
[16:26:23.397] Installing dependencies...
[16:26:40.207] 
[16:26:40.208] added 504 packages in 17s
[16:26:40.209] 
[16:26:40.209] 161 packages are looking for funding
[16:26:40.209]   run `npm fund` for details
[16:26:40.227] Detected Next.js version: 15.1.6
[16:26:40.256] Running "npm run build"
[16:26:40.410] 
[16:26:40.410] > <PROJECT_NAME>@0.1.0 build
[16:26:40.411] > next build
[16:26:40.411] 
[16:26:41.138] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[16:26:41.139] This information is used to shape Next.js' roadmap and prioritize features.
[16:26:41.139] You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
[16:26:41.139] https://nextjs.org/telemetry
[16:26:41.139] 
[16:26:41.192]    â–˛ Next.js 15.1.6
[16:26:41.193] 
[16:26:41.268]    Creating an optimized production build ...
[16:27:14.871]  âś“ Compiled successfully
[16:27:14.877]    Linting and checking validity of types ...
[16:27:15.009] Error: Command "npm run build" exited with 1
[16:27:15.325] 

Configuration

/* package.json */
{
  "name": "<PROJECT_NAME>",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@apollo/client": "^3.12.9",
    "@hookform/resolvers": "^3.10.0",
    "@radix-ui/react-checkbox": "^1.1.3",
    "@radix-ui/react-collapsible": "^1.1.2",
    "@radix-ui/react-dialog": "^1.1.5",
    "@radix-ui/react-dropdown-menu": "^2.1.5",
    "@radix-ui/react-hover-card": "^1.1.5",
    "@radix-ui/react-icons": "^1.3.2",
    "@radix-ui/react-label": "^2.1.1",
    "@radix-ui/react-popover": "^1.1.5",
    "@radix-ui/react-scroll-area": "^1.2.2",
    "@radix-ui/react-select": "^2.1.5",
    "@radix-ui/react-separator": "^1.1.1",
    "@radix-ui/react-slot": "^1.1.1",
    "@radix-ui/react-toggle": "^1.1.1",
    "@radix-ui/react-toggle-group": "^1.1.1",
    "@radix-ui/react-tooltip": "^1.1.7",
    "@tanstack/react-table": "^8.20.6",
    "@types/lodash": "^4.17.15",
    "class-variance-authority": "^0.7.1",
    "clsx": "^2.1.1",
    "cmdk": "^1.0.4",
    "date-fns": "^3.6.0",
    "graphql": "^16.10.0",
    "jwt-decode": "^4.0.0",
    "lodash": "^4.17.21",
    "lucide-react": "^0.474.0",
    "next": "15.1.6",
    "next-themes": "^0.4.4",
    "react": "19.0.0",
    "react-day-picker": "^8.10.1",
    "react-dom": "19.0.0",
    "react-hook-form": "^7.54.2",
    "react-pdf": "^9.2.1",
    "sonner": "^1.7.4",
    "tailwind-merge": "^2.6.0",
    "tailwindcss-animate": "^1.0.7",
    "zod": "^3.24.1",
    "zustand": "^5.0.3"
  },
  "devDependencies": {
    "@types/node": "^22",
    "@types/react": "npm:types-react@19.0.0-alpha.3",
    "@types/react-dom": "npm:types-react-dom@19.0.0-alpha.3",
    "eslint": "^9",
    "eslint-config-next": "15.1.6",
    "postcss": "^8",
    "tailwindcss": "^3.4.17",
    "typescript": "^5.7.3"
  },
  "overrides": {
    "@types/react": "npm:types-react@19.0.0-alpha.3",
    "@types/react-dom": "npm:types-react-dom@19.0.0-alpha.3",
    "react-day-picker": {
      "react": "19.0.0"
    }
  }
}

/* next.config.mjs */

/** @type {import('next').NextConfig} */
const nextConfig = {
};

export default nextConfig;
/* tsconfig.json */
{
  "compilerOptions": {
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": false,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "bundler",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "plugins": [
      {
        "name": "next"
      }
    ],
    "baseUrl": ".",
    "paths": {
      "@/*": ["./*"]
    },
    "target": "ES2017"
  },
  "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
  "exclude": ["node_modules"]
}

Here are logs when running build through local vercel CLI

$ vercel build --debug

Vercel CLI 41.0.0
> [debug] [2025-02-04T23:54:12.278Z] user supplied known subcommand: "build"
> [debug] [2025-02-04T23:54:12.339Z] Found ".git/config" - detected "/Users/<REDACTED>/Developer/<PROJECT_NAME>" as repo root
> [debug] [2025-02-04T23:54:12.343Z] Loaded environment variables from "/Users/<REDACTED>/Developer/<PROJECT_NAME>/.vercel/.env.preview.local"
> [debug] [2025-02-04T23:54:12.347Z] Locating files /Users/<REDACTED>/Developer/<PROJECT_NAME>
> [debug] [2025-02-04T23:54:12.347Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.DS_Store
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.env.local
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.git
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.gitignore
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.gitmodules
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.next
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/.vercel
> [debug] [2025-02-04T23:54:12.348Z] Ignoring /Users/<REDACTED>/Developer/<PROJECT_NAME>/node_modules
> [debug] [2025-02-04T23:54:12.351Z] Locating files /Users/<REDACTED>/Developer/<PROJECT_NAME> [4ms]
> [debug] [2025-02-04T23:54:12.426Z] Imported Builder "@vercel/next" from "/Users/<REDACTED>/Library/pnpm/global/5/.pnpm/@vercel+next@4.5.0/node_modules/@vercel/next"
> [debug] [2025-02-04T23:54:12.436Z] Setting env VERCEL_PROJECT_SETTINGS_NODE_VERSION to "20.x"
> [debug] [2025-02-04T23:54:12.436Z] Building entrypoint "package.json" with "@vercel/next"
WARNING: You should not upload the `.next` directory.
Installing dependencies...

up to date in 449ms

163 packages are looking for funding
  run `npm fund` for details
Detected Next.js version: 15.1.6
Running "npm run build"

> <PROJECT_NAME>@0.1.0 build
> next build

   â–˛ Next.js 15.1.6
   - Environments: .env.local, .env

   Creating an optimized production build ...
 âś“ Compiled successfully
   Linting and checking validity of types  .Error: Command "npm run build" exited with 1
> [debug] [2025-02-04T23:54:17.951Z] Vercel CLI 41.0.0

> [debug] [2025-02-04T23:54:18.282Z] Telemetry event tracked
> [debug] [2025-02-04T23:54:18.437Z] Telemetry subprocess exited with code 0

AWS Amplify deployments show similar behavior, which makes me believe the issue lies on the Next.js side rather than Vercel…

2025-02-04T23:26:44.533Z [INFO]: ## Starting Backend Build
                                 ## Checking for associated backend environment...
                                 ## No backend environment association found, continuing...
                                 ## Completed Backend Build
2025-02-04T23:26:44.538Z [INFO]: {"backendDuration": 0}
                                 ## Starting Frontend Build
                                 # Starting phase: preBuild
                                 # Executing command: nvm use 20
2025-02-04T23:26:53.243Z [INFO]: Now using node v20.9.0 (npm v10.1.0)
2025-02-04T23:26:53.247Z [INFO]: # Completed phase: preBuild
                                 # Starting phase: build
                                 # Executing command: export NODE_OPTIONS=--max-old-space-size=5632
                                 # Executing command: npm i
2025-02-04T23:27:09.066Z [INFO]: added 504 packages, and audited 505 packages in 16s
2025-02-04T23:27:09.073Z [INFO]: 161 packages are looking for funding
                                 run `npm fund` for details
                                 found 0 vulnerabilities
2025-02-04T23:27:09.090Z [INFO]: # Executing command: npm run build
2025-02-04T23:27:09.375Z [INFO]: > <PROJECT_NAME>@0.1.0 build
                                 > next build
2025-02-04T23:27:10.053Z [INFO]: âš  No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
2025-02-04T23:27:10.069Z [INFO]: Attention: Next.js now collects completely anonymous telemetry regarding usage.
2025-02-04T23:27:10.070Z [INFO]: This information is used to shape Next.js' roadmap and prioritize features.
                                 You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
                                 https://nextjs.org/telemetry
2025-02-04T23:27:10.125Z [INFO]: â–˛ Next.js 15.1.6
2025-02-04T23:27:10.125Z [INFO]: 
2025-02-04T23:27:10.196Z [INFO]: Creating an optimized production build ...
2025-02-04T23:27:33.899Z [INFO]: âś“ Compiled successfully
2025-02-04T23:27:33.904Z [INFO]: Linting and checking validity of types ...
2025-02-04T23:27:33.992Z [ERROR]: !!! Build failed
2025-02-04T23:27:33.992Z [INFO]: Please read more about Amplify Hosting's support for SSR frameworks to find if your build failure is related to an unsupported feature: https://docs.aws.amazon.com/amplify/latest/userguide/amplify-ssr-framework-support.html. You may also find this troubleshooting guide useful: https://docs.aws.amazon.com/amplify/latest/userguide/troubleshooting-ssr-deployment.html
2025-02-04T23:27:33.992Z [ERROR]: !!! Error: Command failed with exit code 1
2025-02-04T23:27:33.992Z [INFO]: # Starting environment caching...
2025-02-04T23:27:33.993Z [INFO]: # Environment caching completed

Upon trying deployment to clean EC2 machine using Node.js, the following errors were encountered::

[ec2-user@ip-XXX src]$ npm run build

> <PROJECT_NAME>@0.1.0 build
> next build

Attention: Next.js now collects completely anonymous telemetry regarding usage.
This information is used to shape Next.js' roadmap and prioritize features.
You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
https://nextjs.org/telemetry

   â–˛ Next.js 15.1.6
   - Environments: .env

   Creating an optimized production build ...

<--- Last few GCs --->

[17340:0xaaaae2d9d8e0]    38747 ms: Mark-sweep (reduce) 242.4 (259.0) -> 239.3 (257.2) MB, 978.5 / 0.0 ms  (average mu = 0.345, current mu = 0.260) allocation failure; scavenge might not succeed
[17340:0xaaaae2d9d8e0]    39920 ms: Mark-sweep (reduce) 247.8 (264.4) -> 241.7 (259.6) MB, 1059.2 / 0.0 ms  (average mu = 0.225, current mu = 0.097) allocation failure; scavenge might not succeed


<--- JS stacktrace --->

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
 1: 0xaaaaaf8d5d70 node::Abort() [/usr/bin/node-18]
 2: 0xaaaaaf7cb028  [/usr/bin/node-18]
 3: 0xaaaab013f58c v8::Utils::ReportOOMFailure(v8::internal::Isolate*, char const*, bool) [/usr/bin/node-18]
 4: 0xaaaab013f79c v8::internal::V8::FatalProcessOutOfMemory(v8::internal::Isolate*, char const*, bool) [/usr/bin/node-18]
 5: 0xaaaab0353740 v8::internal::Heap::EnsureFromSpaceIsCommitted() [/usr/bin/node-18]
 6: 0xaaaab0366e2c v8::internal::Heap::CollectGarbage(v8::internal::AllocationSpace, v8::internal::GarbageCollectionReason, v8::GCCallbackFlags) [/usr/bin/node-18]
 7: 0xaaaab033e740 v8::internal::HeapAllocator::AllocateRawWithLightRetrySlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/bin/node-18]
 8: 0xaaaab033f86c v8::internal::HeapAllocator::AllocateRawWithRetryOrFailSlowPath(int, v8::internal::AllocationType, v8::internal::AllocationOrigin, v8::internal::AllocationAlignment) [/usr/bin/node-18]
 9: 0xaaaab031ed2c v8::internal::Factory::AllocateRaw(int, v8::internal::AllocationType, v8::internal::AllocationAlignment) [/usr/bin/node-18]
10: 0xaaaab0314ffc v8::internal::FactoryBase<v8::internal::Factory>::AllocateRawWithImmortalMap(int, v8::internal::AllocationType, v8::internal::Map, v8::internal::AllocationAlignment) [/usr/bin/node-18]
11: 0xaaaab03178b0 v8::internal::FactoryBase<v8::internal::Factory>::NewRawOneByteString(int, v8::internal::AllocationType) [/usr/bin/node-18]
12: 0xaaaab0666808 v8::internal::String::SlowFlatten(v8::internal::Isolate*, v8::internal::Handle<v8::internal::ConsString>, v8::internal::AllocationType) [/usr/bin/node-18]
13: 0xaaaab0669730 v8::internal::String::SlowEquals(v8::internal::Isolate*, v8::internal::Handle<v8::internal::String>, v8::internal::Handle<v8::internal::String>) [/usr/bin/node-18]
14: 0xaaaab078cd1c v8::internal::Runtime_StringEqual(int, unsigned long*, v8::internal::Isolate*) [/usr/bin/node-18]
15: 0xaaaab0b6202c  [/usr/bin/node-18]
Static worker exited with code: null and signal: SIGABRT
1 Like

From the StackOverflow post by @artemnikolenkojohnst:

After spending a lot of time debugging, I solved the issue by changing “build” in package.json to the default command of: "build": "next build".

It seems that npm i was causing an issue.

As you can see in my attached package.json it is already set to next build

1 Like

Hi @artemnikolenkojohnst, we’re trying to understand this issue and I’ll let you know once we have any updates.

Hi @artemnikolenkojohnst –

We’re looking into fixing the bug in Next.js that is causing the errors to be silenced here. In this case, it looks like the error that you should be seeing in your build is as follows:

Please install @types/react by running:

	npm install --save-dev @types/react

If you are not trying to use TypeScript, please remove the tsconfig.json file from your package root (and any TypeScript files in your app and pages directories).

Unless there’s a specific reason, you should be using the latest versions of @types/react and @types/react-dom in Next.js 15. Updating those dependencies and removing the override should hopefully fix your build, but let us know if not!

2 Likes

Thank you, updating @types/react & @types/react-dom did the trick for me.

"devDependencies": {
    "@types/node": "^22",
    "@types/react": "^19.0.8",
    "@types/react-dom": "^19.0.3",
    /* ... */
}
npm install --save-dev @types/react@19.0.8
npm install --save-dev @types/react-dom@19.0.3
3 Likes

still getting this issue. ive updated my types, react and react-dom, still exit 1.