Build script returned non-zero exit code: 1 and 2

Hi! We are moving to Netlify from Vercel and tried to deploy our NextJS app, however we got this error. This works ok in Vercel but build error in Netlify. Any help would be appreciated.

Sitename: project-xyx123.netlify.app

Build Issues on development branch:

9:15:00 AM: build-image version: a89f4ad50402ec92ae85e9b83fc50dcfb293df2e (focal)
9:15:00 AM: buildbot version: a89f4ad50402ec92ae85e9b83fc50dcfb293df2e
9:15:00 AM: Fetching cached dependencies
9:15:00 AM: Starting to download cache of 214.5MB
9:15:02 AM: Finished downloading cache in 1.876s
9:15:02 AM: Starting to extract cache
9:15:04 AM: Finished extracting cache in 1.934s
9:15:04 AM: Finished fetching cache in 3.872s
9:15:04 AM: Starting to prepare the repo for build
9:15:06 AM: Preparing Git Reference refs/heads/develop
9:15:08 AM: Parsing package.json dependencies
9:15:09 AM: Starting to install dependencies
9:15:09 AM: Started restoring cached go cache
9:15:09 AM: Finished restoring cached go cache
9:15:10 AM: Installing Go version 1.19.5 (requested 1.19.5)
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: Using PHP version 8.0
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: go version go1.19.5 linux/amd64
9:15:14 AM: Started restoring cached Node.js version
9:15:15 AM: Finished restoring cached Node.js version
9:15:15 AM: v16.19.1 is already installed.
9:15:16 AM: Now using node v16.19.1 (npm v8.19.3)
9:15:16 AM: Enabling Node.js Corepack
9:15:16 AM: Started restoring cached build plugins
9:15:16 AM: Finished restoring cached build plugins
9:15:16 AM: Started restoring cached corepack dependencies
9:15:16 AM: Finished restoring cached corepack dependencies
9:15:16 AM: No npm workspaces detected
9:15:16 AM: Started restoring cached node modules
9:15:16 AM: Finished restoring cached node modules
9:15:16 AM: Installing npm packages using npm version 8.19.3
9:15:26 AM: added 411 packages, removed 144 packages, changed 199 packages, and audited 1017 packages in 10s
9:15:26 AM: 145 packages are looking for funding
9:15:26 AM: run npm fund for details
9:15:26 AM: 14 vulnerabilities (1 low, 5 moderate, 8 high)
9:15:26 AM: To address issues that do not require attention, run:
9:15:26 AM: npm audit fix
9:15:26 AM: To address all issues (including breaking changes), run:
9:15:26 AM: npm audit fix --force
9:15:26 AM: Run npm audit for details.
9:15:26 AM: npm packages installed
9:15:26 AM: go version go1.19.5 linux/amd64
9:15:26 AM: Python version set to 3.8
9:15:26 AM: go version go1.19.5 linux/amd64
9:15:26 AM: Attempting Ruby version 2.7.2, read from environment
9:15:27 AM: Using Ruby version 2.7.2
9:15:27 AM: go version go1.19.5 linux/amd64
9:15:27 AM: go version go1.19.5 linux/amd64
9:15:28 AM: go version go1.19.5 linux/amd64
9:15:28 AM: Install dependencies script success
9:15:28 AM: Starting build script
9:15:28 AM: Using stage install dependencies
9:15:28 AM: go version go1.19.5 linux/amd64
9:15:28 AM: Detected 1 framework(s)
9:15:28 AM: “next” at version “13.0.5”
9:15:28 AM: Section completed: initializing
9:15:30 AM: ​
9:15:30 AM: Netlify Build
9:15:30 AM: ────────────────────────────────────────────────────────────────
9:15:30 AM: ​
9:15:30 AM: ❯ Version
9:15:30 AM: @netlify/build 29.7.1
9:15:30 AM: ​
9:15:30 AM: ❯ Flags
9:15:30 AM: baseRelDir: true
9:15:30 AM: buildId: 641ba8126cec183d0d6f002e
9:15:30 AM: deployId: 641ba8126cec183d0d6f0030
9:15:30 AM: ​
9:15:30 AM: ❯ Current directory
9:15:30 AM: /opt/build/repo
9:15:30 AM: ​
9:15:30 AM: ❯ Config file
9:15:30 AM: No config file was defined: using default values.
9:15:30 AM: ​
9:15:30 AM: ❯ Context
9:15:30 AM: branch-deploy
9:15:30 AM: ​
9:15:30 AM: ❯ Using Next.js Runtime - v4.32.2
9:15:31 AM: ​
9:15:31 AM: 1. @netlify/plugin-nextjs (onPreBuild event)
9:15:31 AM: ────────────────────────────────────────────────────────────────
9:15:31 AM: ​
9:15:31 AM: Next.js cache restored.
9:15:31 AM: Not running Next Runtime
9:15:31 AM: ​
9:15:31 AM: (@netlify/plugin-nextjs onPreBuild completed in 72ms)
9:15:31 AM: ​
9:15:31 AM: 2. Build command from Netlify app
9:15:31 AM: ────────────────────────────────────────────────────────────────
9:15:31 AM: ​
9:15:31 AM: $ npm run build
9:15:31 AM: > project-x-website@0.1.0 build
9:15:31 AM: > next build
9:15:32 AM: info - Linting and checking validity of types…
9:15:39 AM: info - Creating an optimized production build…
9:15:51 AM: Failed to compile.
9:15:51 AM:
9:15:51 AM: ./public/assets/Human.webp
9:15:51 AM: RuntimeError: unreachable
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[40]:0x6c03
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[98]:0x77d4
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[63]:0x745c
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[68]:0x7544
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[61]:0x73e4
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[87]:0x7750
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[33]:0x6830
9:15:51 AM: at wasm://wasm/000242f2:wasm-function[0]:0x260
9:15:51 AM: at Object.resize (/opt/build/repo/node_modules/next/dist/server/lib/squoosh/resize/squoosh_resize.js:45:14)
9:15:51 AM: at /opt/build/repo/node_modules/next/dist/server/lib/squoosh/codecs.js:126:65
9:15:51 AM: Import trace for requested module:
9:15:51 AM: ./public/assets/Human.webp
9:15:51 AM: ./components/landing/Home.tsx
9:15:51 AM: > Build failed because of webpack errors
9:15:51 AM: ​
9:15:51 AM: “build.command” failed
9:15:51 AM: ────────────────────────────────────────────────────────────────
9:15:51 AM: ​
9:15:51 AM: Error message
9:15:51 AM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
9:15:51 AM: ​
9:15:51 AM: Error location
9:15:51 AM: In Build command from Netlify app:
9:15:51 AM: npm run build
9:15:51 AM: ​
9:15:51 AM: Resolved config
9:15:51 AM: build:
9:15:52 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
9:15:51 AM: command: npm run build
9:15:51 AM: commandOrigin: ui
9:15:51 AM: environment:
9:15:51 AM: - REDACTED ENV KEY NAMES
9:15:51 AM: publish: /opt/build/repo/.next
9:15:51 AM: publishOrigin: ui
9:15:51 AM: plugins:
9:15:51 AM: - inputs: {}
9:15:51 AM: origin: ui
9:15:51 AM: package: ‘@netlify/plugin-nextjs’
9:15:51 AM: Caching artifacts
9:15:51 AM: Started saving node modules
9:15:51 AM: Finished saving node modules
9:15:51 AM: Started saving build plugins
9:15:51 AM: Finished saving build plugins
9:15:51 AM: Started saving corepack cache
9:15:51 AM: Finished saving corepack cache
9:15:51 AM: Started saving pip cache
9:15:51 AM: Finished saving pip cache
9:15:51 AM: Started saving emacs cask dependencies
9:15:51 AM: Finished saving emacs cask dependencies
9:15:51 AM: Started saving maven dependencies
9:15:51 AM: Finished saving maven dependencies
9:15:51 AM: Started saving boot dependencies
9:15:51 AM: Finished saving boot dependencies
9:15:51 AM: Started saving rust rustup cache
9:15:51 AM: Finished saving rust rustup cache
9:15:51 AM: Started saving go dependencies
9:15:51 AM: Finished saving go dependencies
9:15:52 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:15:52 AM: Failing build: Failed to build site
9:15:52 AM: Finished processing build request in 52.088s

Hello @chie,

My first question would be if you’ve checked the NODE_VERSION Is it the same in Netlify as you’re using locally during development?

Gr,

Andy

Hi @chie :wave:t6: ,

Welcome to the Netlify support forums and thanks so much for reaching out. To add to Andy’s request. I’m curious… what are your build settings?

Locally - 16.17.0
What does Netlify use right now?

Hi @Sam0, here’s our build settings. :slight_smile:

Maybe try setting the NODE_VERSION in your configuration to the same version as your local machine.

Or in your netlify.toml

Gr,

Andy