Home
Support Forums

Build failed due to a user error: Build script returned non-zero exit code: 2

I’ve got an error continuously
plz help me

Here is relavant code https://github.com/jiseon-baek/Music-Tag-App

11:22:56 PM: Build ready to start
11:22:58 PM: build-image version: c5b01a919d3e16af69445c5de0cacb49efbb1a23 (focal)
11:22:58 PM: build-image tag: v4.4.0
11:22:58 PM: buildbot version: f54abf87fe81303255850790eebe8dc0b2826706
11:22:58 PM: Fetching cached dependencies
11:22:58 PM: Failed to fetch cache, continuing with build
11:22:58 PM: Starting to prepare the repo for build
11:22:58 PM: No cached dependencies found. Cloning fresh repo
11:22:58 PM: git clone GitHub - jiseon-baek/Music-Tag-App: Using React + Redux, Node, Express, MongoDB
11:23:00 PM: Preparing Git Reference refs/heads/master
11:23:01 PM: Parsing package.json dependencies
11:23:02 PM: Starting build script
11:23:02 PM: Installing dependencies
11:23:02 PM: Python version set to 2.7
11:23:02 PM: Downloading and installing node v16.13.0…
11:23:03 PM: Downloading https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz
11:23:03 PM: Computing checksum with sha256sum
11:23:03 PM: Checksums matched!
11:23:06 PM: Now using node v16.13.0 (npm v8.1.0)
11:23:07 PM: Started restoring cached build plugins
11:23:07 PM: Finished restoring cached build plugins
11:23:07 PM: Attempting ruby version 2.7.2, read from environment
11:23:08 PM: Using ruby version 2.7.2
11:23:09 PM: Using PHP version 8.0
11:23:09 PM: Started restoring cached go cache
11:23:09 PM: Finished restoring cached go cache
11:23:09 PM: go version go1.16.5 linux/amd64
11:23:09 PM: go version go1.16.5 linux/amd64
11:23:09 PM: Installing missing commands
11:23:09 PM: Verify run directory
11:23:10 PM: ​
11:23:10 PM: ────────────────────────────────────────────────────────────────
11:23:10 PM: Netlify Build
11:23:10 PM: ────────────────────────────────────────────────────────────────
11:23:10 PM: ​
11:23:10 PM: ❯ Version
11:23:10 PM: @netlify/build 18.21.4
11:23:10 PM: ​
11:23:10 PM: ❯ Flags
11:23:10 PM: baseRelDir: true
11:23:10 PM: buildId: 61853e3f5491a500089685d9
11:23:10 PM: deployId: 61853e3f5491a500089685db
11:23:10 PM: ​
11:23:10 PM: ❯ Current directory
11:23:10 PM: /opt/build/repo
11:23:10 PM: ​
11:23:10 PM: ❯ Config file
11:23:10 PM: No config file was defined: using default values.
11:23:10 PM: ​
11:23:10 PM: ❯ Context
11:23:10 PM: production
11:23:10 PM: ​
11:23:10 PM: ────────────────────────────────────────────────────────────────
11:23:10 PM: 1. Build command from Netlify app
11:23:10 PM: ────────────────────────────────────────────────────────────────
11:23:10 PM: ​
11:23:10 PM: $ CI=npm run build
11:23:10 PM: bash: run: command not found
11:23:10 PM: ​
11:23:10 PM: ────────────────────────────────────────────────────────────────
11:23:10 PM: “build.command” failed
11:23:10 PM: ────────────────────────────────────────────────────────────────
11:23:10 PM: ​
11:23:10 PM: Error message
11:23:10 PM: Command failed with exit code 127: CI=npm run build
11:23:10 PM: ​
11:23:10 PM: Error location
11:23:10 PM: In Build command from Netlify app:
11:23:10 PM: CI=npm run build
11:23:10 PM: ​
11:23:10 PM: Resolved config
11:23:10 PM: build:
11:23:10 PM: command: CI=npm run build
11:23:10 PM: commandOrigin: ui
11:23:10 PM: environment:
11:23:10 PM: - CI
11:23:10 PM: publish: /opt/build/repo/dist
11:23:10 PM: publishOrigin: ui
11:23:11 PM: Caching artifacts
11:23:11 PM: Started saving build plugins
11:23:11 PM: Finished saving build plugins
11:23:11 PM: Started saving pip cache
11:23:11 PM: Finished saving pip cache
11:23:11 PM: Started saving emacs cask dependencies
11:23:11 PM: Finished saving emacs cask dependencies
11:23:11 PM: Started saving maven dependencies
11:23:11 PM: Finished saving maven dependencies
11:23:11 PM: Started saving boot dependencies
11:23:11 PM: Finished saving boot dependencies
11:23:11 PM: Started saving rust rustup cache
11:23:11 PM: Finished saving rust rustup cache
11:23:11 PM: Started saving go dependencies
11:23:11 PM: Finished saving go dependencies
11:23:14 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:23:14 PM: Creating deploy upload records
11:23:14 PM: Failing build: Failed to build site
11:23:14 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
11:23:14 PM: Finished processing build request in 16.102949526s

p.s. I’ve already added ’ Build command: CI=npm run build’ .

It should be CI= npm run build (note the space).

I changed it. And it returns ’ Command failed with exit code 254: CI= npm run build’ this error :joy_cat:

Could you paste the entire log?

2:23:22 AM: Build ready to start
2:23:24 AM: build-image version: c5b01a919d3e16af69445c5de0cacb49efbb1a23 (focal)
2:23:24 AM: build-image tag: v4.4.0
2:23:24 AM: buildbot version: f54abf87fe81303255850790eebe8dc0b2826706
2:23:24 AM: Fetching cached dependencies
2:23:24 AM: Failed to fetch cache, continuing with build
2:23:24 AM: Starting to prepare the repo for build
2:23:24 AM: No cached dependencies found. Cloning fresh repo
2:23:24 AM: git clone GitHub - jiseon-baek/Music-Tag-App: Using React + Redux, Node, Express, MongoDB
2:23:26 AM: Preparing Git Reference refs/heads/master
2:23:27 AM: Parsing package.json dependencies
2:23:27 AM: Starting build script
2:23:27 AM: Installing dependencies
2:23:27 AM: Python version set to 2.7
2:23:28 AM: Downloading and installing node v16.13.0…
2:23:28 AM: Downloading https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz
2:23:29 AM: Computing checksum with sha256sum
2:23:29 AM: Checksums matched!
2:23:32 AM: Now using node v16.13.0 (npm v8.1.0)
2:23:32 AM: Started restoring cached build plugins
2:23:32 AM: Finished restoring cached build plugins
2:23:32 AM: Attempting ruby version 2.7.2, read from environment
2:23:33 AM: Using ruby version 2.7.2
2:23:34 AM: Using PHP version 8.0
2:23:34 AM: Started restoring cached go cache
2:23:34 AM: Finished restoring cached go cache
2:23:34 AM: go version go1.16.5 linux/amd64
2:23:34 AM: go version go1.16.5 linux/amd64
2:23:34 AM: Installing missing commands
2:23:34 AM: Verify run directory
2:23:35 AM: ​
2:23:35 AM: ────────────────────────────────────────────────────────────────
2:23:35 AM: Netlify Build
2:23:35 AM: ────────────────────────────────────────────────────────────────
2:23:35 AM: ​
2:23:35 AM: ❯ Version
2:23:35 AM: @netlify/build 18.21.4
2:23:35 AM: ​
2:23:35 AM: ❯ Flags
2:23:35 AM: baseRelDir: true
2:23:35 AM: buildId: 6185688a7320370007f54007
2:23:35 AM: deployId: 6185688a7320370007f54009
2:23:35 AM: ​
2:23:35 AM: ❯ Current directory
2:23:35 AM: /opt/build/repo
2:23:35 AM: ​
2:23:35 AM: ❯ Config file
2:23:35 AM: No config file was defined: using default values.
2:23:35 AM: ​
2:23:35 AM: ❯ Context
2:23:35 AM: production
2:23:35 AM: ​
2:23:35 AM: ────────────────────────────────────────────────────────────────
2:23:35 AM: 1. Build command from Netlify app
2:23:35 AM: ────────────────────────────────────────────────────────────────
2:23:35 AM: ​
2:23:35 AM: $ CI= npm run build
2:23:36 AM: npm ERR! code ENOENT
2:23:36 AM: npm ERR! syscall open
2:23:36 AM: npm ERR! path /opt/build/repo/package.json
2:23:36 AM: npm ERR! errno -2
2:23:36 AM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
2:23:36 AM: npm ERR! enoent This is related to npm not being able to find a file.
2:23:36 AM: npm ERR! enoent
2:23:36 AM: npm ERR! A complete log of this run can be found in:
2:23:36 AM: npm ERR! /opt/buildhome/.npm/_logs/2021-11-05T17_23_36_353Z-debug.log
2:23:36 AM: ​
2:23:36 AM: ────────────────────────────────────────────────────────────────
2:23:36 AM: “build.command” failed
2:23:36 AM: ────────────────────────────────────────────────────────────────
2:23:36 AM: ​
2:23:36 AM: Error message
2:23:36 AM: Command failed with exit code 254: CI= npm run build
2:23:36 AM: ​
2:23:36 AM: Error location
2:23:36 AM: In Build command from Netlify app:
2:23:36 AM: CI= npm run build
2:23:36 AM: ​
2:23:36 AM: Resolved config
2:23:36 AM: build:
2:23:36 AM: command: CI= npm run build
2:23:36 AM: commandOrigin: ui
2:23:36 AM: environment:
2:23:36 AM: - CI
2:23:36 AM: publish: /opt/build/repo/dist
2:23:36 AM: publishOrigin: ui
2:23:36 AM: Caching artifacts
2:23:36 AM: Started saving build plugins
2:23:36 AM: Finished saving build plugins
2:23:36 AM: Started saving pip cache
2:23:36 AM: Finished saving pip cache
2:23:36 AM: Started saving emacs cask dependencies
2:23:36 AM: Finished saving emacs cask dependencies
2:23:36 AM: Started saving maven dependencies
2:23:36 AM: Finished saving maven dependencies
2:23:36 AM: Started saving boot dependencies
2:23:36 AM: Finished saving boot dependencies
2:23:36 AM: Started saving rust rustup cache
2:23:36 AM: Finished saving rust rustup cache
2:23:36 AM: Started saving go dependencies
2:23:36 AM: Finished saving go dependencies
2:23:39 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:23:39 AM: Creating deploy upload records
2:23:39 AM: Failing build: Failed to build site
2:23:39 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
2:23:39 AM: Finished processing build request in 15.074122982s

Your repo doesn’t seem to have a package.json.

Looks like your frontend lives in the client folder on your repo:

You need to change the base path in site settings to client.

Successfully build! Thank you @hrishikesh