Debugging: Build failed non-zero exit code 2 and exit code 254

Having issues deploying site. Have read other support posts and made suggested changes. In my package.json file the production script “npm run prod”, but when I put this in the settings as the build script it didn’t work. So also tried “npm run build” - didn’t work. Cleared cache each time to attempt redeploy (switching between npm run build and npm run prod, and adding nft-minting-app-main).

Build log below:
10:53:56 AM: Build ready to start
10:54:03 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
10:54:03 AM: build-image tag: v4.8.0
10:54:03 AM: buildbot version: 13616ca0f4280331d49967e190a04e108291d30c
10:54:03 AM: Building without cache
10:54:03 AM: Starting to prepare the repo for build
10:54:04 AM: No cached dependencies found. Cloning fresh repo
10:54:04 AM: git clone https://github.com/DavidM0709/doubletap-frontend
10:54:04 AM: Preparing Git Reference refs/heads/main
10:54:05 AM: Parsing package.json dependencies
10:54:05 AM: Starting build script
10:54:05 AM: Installing dependencies
10:54:05 AM: Python version set to 2.7
10:54:06 AM: Downloading and installing node v16.15.0…
10:54:06 AM: Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz
10:54:07 AM: Computing checksum with sha256sum
10:54:07 AM: Checksums matched!
10:54:09 AM: Now using node v16.15.0 (npm v8.5.5)
10:54:09 AM: Started restoring cached build plugins
10:54:09 AM: Finished restoring cached build plugins
10:54:09 AM: Attempting ruby version 2.7.2, read from environment
10:54:10 AM: Using ruby version 2.7.2
10:54:11 AM: Using PHP version 8.0
10:54:11 AM: Started restoring cached go cache
10:54:11 AM: Finished restoring cached go cache
10:54:11 AM: go version go1.16.5 linux/amd64
10:54:11 AM: go version go1.16.5 linux/amd64
10:54:11 AM: Installing missing commands
10:54:11 AM: Verify run directory
10:54:12 AM: ​
10:54:12 AM: ────────────────────────────────────────────────────────────────
10:54:12 AM: Netlify Build
10:54:12 AM: ────────────────────────────────────────────────────────────────
10:54:12 AM: ​
10:54:12 AM: ❯ Version
10:54:12 AM: @netlify/build 27.1.1
10:54:12 AM: ​
10:54:12 AM: ❯ Flags
10:54:12 AM: baseRelDir: true
10:54:12 AM: buildId: 628595247bc87c00772e5ac9
10:54:12 AM: deployId: 628595247bc87c00772e5acb
10:54:12 AM: ​
10:54:12 AM: ❯ Current directory
10:54:12 AM: /opt/build/repo
10:54:12 AM: ​
10:54:12 AM: ❯ Config file
10:54:12 AM: No config file was defined: using default values.
10:54:12 AM: ​
10:54:12 AM: ❯ Context
10:54:12 AM: production
10:54:12 AM: ​
10:54:12 AM: ────────────────────────────────────────────────────────────────
10:54:12 AM: 1. Build command from Netlify app
10:54:12 AM: ────────────────────────────────────────────────────────────────
10:54:12 AM: ​
10:54:12 AM: $ npm run build
10:54:12 AM: npm ERR! code ENOENT
10:54:12 AM: npm ERR! syscall open
10:54:12 AM: npm ERR! path /opt/build/repo/package.json
10:54:12 AM: npm ERR! errno -2
10:54:12 AM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
10:54:12 AM: npm ERR! enoent This is related to npm not being able to find a file.
10:54:12 AM: npm ERR! enoent
10:54:12 AM: npm ERR! A complete log of this run can be found in:
10:54:12 AM: npm ERR! /opt/buildhome/.npm/_logs/2022-05-19T00_54_12_809Z-debug-0.log
10:54:12 AM: ​
10:54:12 AM: ────────────────────────────────────────────────────────────────
10:54:12 AM: “build.command” failed
10:54:12 AM: ────────────────────────────────────────────────────────────────
10:54:12 AM: ​
10:54:12 AM: Error message
10:54:12 AM: Command failed with exit code 254: npm run build (Search results for '"non-zero exit code: 254"' - Netlify Support Forums)
10:54:12 AM: ​
10:54:12 AM: Error location
10:54:12 AM: In Build command from Netlify app:
10:54:12 AM: npm run build
10:54:12 AM: ​
10:54:12 AM: Resolved config
10:54:12 AM: build:
10:54:12 AM: command: npm run build
10:54:12 AM: commandOrigin: ui
10:54:12 AM: publish: /opt/build/repo/nft-minting-app-main
10:54:12 AM: publishOrigin: ui
10:54:13 AM: Caching artifacts
10:54:13 AM: Started saving build plugins
10:54:13 AM: Finished saving build plugins
10:54:13 AM: Started saving pip cache
10:54:13 AM: Finished saving pip cache
10:54:13 AM: Started saving emacs cask dependencies
10:54:13 AM: Finished saving emacs cask dependencies
10:54:14 AM: Creating deploy upload records
10:54:13 AM: Started saving maven dependencies
10:54:13 AM: Finished saving maven dependencies
10:54:13 AM: Started saving boot dependencies
10:54:13 AM: Finished saving boot dependencies
10:54:13 AM: Started saving rust rustup cache
10:54:15 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)
10:54:13 AM: Finished saving rust rustup cache
10:54:13 AM: Started saving go dependencies
10:54:13 AM: Finished saving go dependencies
10:54:14 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:54:15 AM: Failing build: Failed to build site
10:54:15 AM: Finished processing build request in 11.716847704s

TIA.
Davo

Hey @Davo

The cause here is there is no package.json file at the root of the repository you are deploying from. The likely cause is the code exists in a sub-directory within the repository. If this is the case, you need to set the base directory in the build settings to that of the sub-directory name.

Hi @coelmay,

I’ve tried adding the base directory in the build settings and I get the following:
11:39:53 AM: Build ready to start

11:39:55 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)

11:39:55 AM: build-image tag: v4.8.0

11:39:55 AM: buildbot version: 13616ca0f4280331d49967e190a04e108291d30c

11:39:55 AM: Fetching cached dependencies

11:39:55 AM: Failed to fetch cache, continuing with build

11:39:55 AM: Starting to prepare the repo for build

11:39:55 AM: No cached dependencies found. Cloning fresh repo

11:39:55 AM: git clone https://github.com/DavidM0709/doubletap-frontend

11:39:56 AM: Preparing Git Reference refs/heads/main

11:39:56 AM: Parsing package.json dependencies

11:39:57 AM: Creating deploy upload records

11:39:57 AM: Failing build: Failed to parse configuration

11:39:57 AM: Failed during stage ‘Reading and parsing configuration files’:
When resolving config:
Base directory does not exist: /opt/build/repo/doubletap-frontend

: exit status 1

11:39:57 AM: Finished processing build request in 2.255419208s

I guess I’m adding the wrong info? in Git the file path is


main > doubletap-frontend/Desktop/doubletap-spa/doubletap-spa-frontend

and that displays the dist and package.json at the same level.

It appears that you’ve resolved the issue. Do you still need help?