Deploy error error - npm ERR! enoent ENOENT: no such file or directory, open '/opt/build/repo/package.json'

Hi everyone, I’m having issues deploying my nft site.
My site is: https://nfttesting.netlify.app, and I’m getting this error message: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’

But the file is there. Would really appreciate any help I could get. Thanks in advanced

11:00:11 AM: Build ready to start
11:00:22 AM: build-image version: d2c6dbeac570350a387d832f64bc980dc964ad65 (focal)
11:00:22 AM: build-image tag: v4.8.0
11:00:22 AM: buildbot version: a018caed2ab46726023e1532e0d3214727318b1c
11:00:23 AM: Building without cache
11:00:23 AM: Starting to prepare the repo for build
11:00:23 AM: No cached dependencies found. Cloning fresh repo
11:00:23 AM: git clone https://github.com/CCantoMAG/LazyLenny
11:00:26 AM: Preparing Git Reference refs/heads/main
11:00:27 AM: Parsing package.json dependencies
11:00:28 AM: Different build dir detected, going to use the one specified in the Netlify configuration file: ‘’ versus ‘/’ in the Netlify UI
11:00:28 AM: Starting build script
11:00:28 AM: Installing dependencies
11:00:28 AM: Python version set to 2.7
11:00:29 AM: Downloading and installing node v16.15.0…
11:00:30 AM: Downloading https://nodejs.org/dist/v16.15.0/node-v16.15.0-linux-x64.tar.xz
11:00:30 AM: Computing checksum with sha256sum
11:00:30 AM: Checksums matched!
11:00:34 AM: Now using node v16.15.0 (npm v8.5.5)
11:00:34 AM: Started restoring cached build plugins
11:00:34 AM: Finished restoring cached build plugins
11:00:34 AM: Attempting ruby version 2.7.2, read from environment
11:00:36 AM: Using ruby version 2.7.2
11:00:37 AM: Using PHP version 8.0
11:00:37 AM: Started restoring cached go cache
11:00:37 AM: Finished restoring cached go cache
11:00:37 AM: go version go1.16.5 linux/amd64
11:00:37 AM: go version go1.16.5 linux/amd64
11:00:37 AM: Installing missing commands
11:00:37 AM: Verify run directory
11:00:39 AM: ​
11:00:39 AM: ────────────────────────────────────────────────────────────────
11:00:39 AM: Netlify Build
11:00:39 AM: ────────────────────────────────────────────────────────────────
11:00:39 AM: ​
11:00:39 AM: ❯ Version
11:00:39 AM: @netlify/build 27.0.2
11:00:39 AM: ​
11:00:39 AM: ❯ Flags
11:00:39 AM: baseRelDir: true
11:00:39 AM: buildId: 627294fbaa5882113301a578
11:00:39 AM: deployId: 627294fbaa5882113301a57a
11:00:39 AM: ​
11:00:39 AM: ❯ Current directory
11:00:39 AM: /opt/build/repo
11:00:39 AM: ​
11:00:39 AM: ❯ Config file
11:00:39 AM: No config file was defined: using default values.
11:00:39 AM: ​
11:00:39 AM: ❯ Context
11:00:39 AM: production
11:00:39 AM: ​
11:00:39 AM: ────────────────────────────────────────────────────────────────
11:00:39 AM: 1. Build command from Netlify app
11:00:39 AM: ────────────────────────────────────────────────────────────────
11:00:39 AM: ​
11:00:39 AM: $ npm run build
11:00:40 AM: npm ERR! code ENOENT
11:00:40 AM: npm ERR! syscall open
11:00:40 AM: npm ERR! path /opt/build/repo/package.json
11:00:40 AM: npm ERR! errno -2
11:00:40 AM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
11:00:40 AM: npm ERR! enoent This is related to npm not being able to find a file.
11:00:40 AM: npm ERR! enoent
11:00:40 AM: npm ERR! A complete log of this run can be found in:
11:00:40 AM: npm ERR! /opt/buildhome/.npm/_logs/2022-05-04T15_00_39_705Z-debug-0.log
11:00:40 AM: ​
11:00:40 AM: ────────────────────────────────────────────────────────────────
11:00:40 AM: “build.command” failed
11:00:40 AM: ────────────────────────────────────────────────────────────────
11:00:40 AM: ​
11:00:40 AM: Error message
11:00:40 AM: Command failed with exit code 254: npm run build (Search results for '"non-zero exit code: 254"' - Netlify Support Forums)
11:00:40 AM: ​
11:00:40 AM: Error location
11:00:40 AM: In Build command from Netlify app:
11:00:40 AM: npm run build
11:00:40 AM: ​
11:00:40 AM: Resolved config
11:00:40 AM: build:
11:00:40 AM: base: /opt/build/repo
11:00:40 AM: command: npm run build
11:00:40 AM: commandOrigin: ui
11:00:40 AM: publish: /opt/build/repo/build
11:00:40 AM: publishOrigin: ui
11:00:40 AM: Caching artifacts
11:00:40 AM: Started saving build plugins
11:00:40 AM: Finished saving build plugins
11:00:40 AM: Started saving pip cache
11:00:40 AM: Finished saving pip cache
11:00:40 AM: Started saving emacs cask dependencies
11:00:40 AM: Finished saving emacs cask dependencies
11:00:40 AM: Started saving maven dependencies
11:00:40 AM: Finished saving maven dependencies
11:00:40 AM: Started saving boot dependencies
11:00:40 AM: Finished saving boot dependencies
11:00:40 AM: Started saving rust rustup cache
11:00:40 AM: Finished saving rust rustup cache
11:00:40 AM: Started saving go dependencies
11:00:40 AM: Finished saving go dependencies
11:00:42 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:00:42 AM: Creating deploy upload records
11:00:42 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)
11:00:42 AM: Failing build: Failed to build site
11:00:42 AM: Finished processing build request in 20.020671075s

The better the post - the faster the answer.

Hey @CCAN

This error message indicates there is no package.json at the root of the repository you are deploying. Likely it is in a sub-directory and as such you shall need to set the base directory.

1 Like