Command failed with exit code 254: CI= npm run build (https://ntl.fyi/exit-code-254)

Problem with build

1:57:11 PM: Waiting for other deploys from your team to complete. Check the queue: Netlify App
1:57:32 PM: Build ready to start
1:57:38 PM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
1:57:38 PM: build-image tag: v4.8.0
1:57:38 PM: buildbot version: e552b142336b2b1222a93a4fd4cbed0019c77b46
1:57:38 PM: Fetching cached dependencies
1:57:38 PM: Starting to download cache of 187.4MB
1:57:40 PM: Finished downloading cache in 1.986926042s
1:57:40 PM: Starting to extract cache
1:57:46 PM: Finished extracting cache in 5.939745876s
1:57:46 PM: Finished fetching cache in 7.951498793s
1:57:46 PM: Starting to prepare the repo for build
1:57:46 PM: Preparing Git Reference pull/103/head
1:57:47 PM: Parsing package.json dependencies
1:57:47 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: ‘’ versus ‘front-end’ in the Netlify UI
1:57:47 PM: Starting build script
1:57:47 PM: Installing dependencies
1:57:47 PM: Python version set to 2.7
1:57:47 PM: Started restoring cached node version
1:57:49 PM: Finished restoring cached node version
1:57:49 PM: v16.14.2 is already installed.
1:57:49 PM: Now using node v16.14.2 (npm v8.5.0)
1:57:49 PM: Started restoring cached build plugins
1:57:49 PM: Finished restoring cached build plugins
1:57:50 PM: Attempting ruby version 2.7.2, read from environment
1:57:51 PM: Using ruby version 2.7.2
1:57:51 PM: Using PHP version 8.0
1:57:51 PM: Started restoring cached go cache
1:57:51 PM: Finished restoring cached go cache
1:57:51 PM: go version go1.16.5 linux/amd64
1:57:51 PM: go version go1.16.5 linux/amd64
1:57:51 PM: Installing missing commands
1:57:51 PM: Verify run directory
1:57:52 PM: ​
1:57:52 PM: ────────────────────────────────────────────────────────────────
1:57:52 PM: Netlify Build
1:57:52 PM: ────────────────────────────────────────────────────────────────
1:57:52 PM: ​
1:57:52 PM: ❯ Version
1:57:52 PM: @netlify/build 26.5.2
1:57:52 PM: ​
1:57:52 PM: ❯ Flags
1:57:52 PM: baseRelDir: true
1:57:52 PM: buildId: 624cad27cd438a0009b26651
1:57:52 PM: deployId: 624cad27cd438a0009b26653
1:57:52 PM: ​
1:57:52 PM: ❯ Current directory
1:57:52 PM: /opt/build/repo
1:57:52 PM: ​
1:57:52 PM: ❯ Config file
1:57:52 PM: No config file was defined: using default values.
1:57:52 PM: ​
1:57:52 PM: ❯ Context
1:57:52 PM: deploy-preview
1:57:52 PM: ​
1:57:52 PM: ────────────────────────────────────────────────────────────────
1:57:52 PM: 1. Build command from Netlify app
1:57:52 PM: ────────────────────────────────────────────────────────────────
1:57:52 PM: ​
1:57:52 PM: $ CI= npm run build
1:57:52 PM: npm ERR! code ENOENT
1:57:52 PM: npm ERR! syscall open
1:57:52 PM: npm ERR! path /opt/build/repo/package.json
1:57:52 PM: npm ERR! errno -2
1:57:52 PM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
1:57:52 PM: npm ERR! enoent This is related to npm not being able to find a file.
1:57:52 PM: npm ERR! enoent
1:57:52 PM: npm ERR! A complete log of this run can be found in:
1:57:52 PM: npm ERR! /opt/buildhome/.npm/_logs/2022-04-05T20_57_52_764Z-debug-0.log
1:57:52 PM: ​
1:57:52 PM: ────────────────────────────────────────────────────────────────
1:57:52 PM: “build.command” failed
1:57:52 PM: ────────────────────────────────────────────────────────────────
1:57:52 PM: ​
1:57:52 PM: Error message
1:57:52 PM: Command failed with exit code 254: CI= npm run build (Search results for '"non-zero exit code: 254"' - Netlify Support Forums)
1:57:52 PM: ​
1:57:52 PM: Error location
1:57:52 PM: In Build command from Netlify app:
1:57:52 PM: CI= npm run build
1:57:52 PM: ​
1:57:52 PM: Resolved config
1:57:52 PM: build:
1:57:52 PM: base: /opt/build/repo
1:57:52 PM: command: CI= npm run build
1:57:52 PM: commandOrigin: ui
1:57:52 PM: environment:
1:57:52 PM: - REACT_APP_API_BASE_URL
1:57:52 PM: - REACT_APP_GOOGLE_KEY
1:57:52 PM: - REVIEW_ID
1:57:52 PM: publish: /opt/build/repo/build
1:57:52 PM: publishOrigin: ui
1:57:53 PM: Caching artifacts
1:57:53 PM: Started saving node modules
1:57:55 PM: Finished saving node modules
1:57:55 PM: Started saving build plugins
1:57:55 PM: Finished saving build plugins
1:57:55 PM: Started saving pip cache
1:57:55 PM: Finished saving pip cache
1:57:55 PM: Started saving emacs cask dependencies
1:57:55 PM: Creating deploy upload records
1:57:55 PM: Finished saving emacs cask dependencies
1:57:55 PM: Started saving maven dependencies
1:57:55 PM: Finished saving maven dependencies
1:57:55 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
1:57:55 PM: Started saving boot dependencies
1:57:55 PM: Finished saving boot dependencies
1:57:55 PM: Started saving rust rustup cache
1:57:55 PM: Finished saving rust rustup cache
1:57:55 PM: Started saving go dependencies
1:57:55 PM: Finished saving go dependencies
1:57:55 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:57:55 PM: Failing build: Failed to build site

Hey @andrewbidylo

The error here is there is no package.json in the root of the repository. Does the code you wish to build exist at the repository root or in a sub-directory?

You can find further troubleshooting assistance via

and also

Yeah, my package.json in the sub-directory ‘front-end’

Then you need to set the base directory to front-end as per this documentation

I’ve already tried it.

And do you receive the same deploy error after changing the base directory?

I’ve got this error when I already had these settings.

Can you share the repository?

sure. GitHub - mrman511/pill-popper at Production

You are overriding the base build directory. It shows this in the logs here:

1:57:47 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: ‘’ versus ‘front-end’ in the Netlify UI

To fix this, correct the setting in netlify.toml here:

You can either delete that line or change it to

  base = "front-end"
1 Like