No such file or directory, open '/opt/build/repo/package.json'

I get the build message:

npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’

But I definitely have a package.json at the root of my project.

There are several other posts for people who are either a) missing the file and need one, or b) don’t need the file because they’re not using npm. But I can’t understand why it’s not finding the file when it’s actually there.

Here’s the full error log, but it’s also publicly available at the build log url above

2:26:27 PM: Build ready to start
2:26:29 PM: build-image version: ac716c5be7f79fe384a0f3759e8ef612cb821a37 (xenial)
2:26:29 PM: build-image tag: v3.13.0
2:26:29 PM: buildbot version: ed990b4b6588208e959ba45b6b7b05738f8b6004
2:26:29 PM: Fetching cached dependencies
2:26:29 PM: Failed to fetch cache, continuing with build
2:26:29 PM: Starting to prepare the repo for build
2:26:29 PM: No cached dependencies found. Cloning fresh repo
2:26:29 PM: git clone https://github.com/KyleMit/kylemit
2:26:29 PM: Preparing Git Reference refs/heads/main
2:26:30 PM: Parsing package.json dependencies
2:26:30 PM: Starting build script
2:26:31 PM: Installing dependencies
2:26:31 PM: Python version set to 2.7
2:26:32 PM: Downloading and installing node v10.24.1...
2:26:32 PM: Downloading https://nodejs.org/dist/v10.24.1/node-v10.24.1-linux-x64.tar.xz...
2:26:32 PM: Computing checksum with sha256sum
2:26:32 PM: Checksums matched!
2:26:34 PM: Now using node v10.24.1 (npm v6.14.12)
2:26:34 PM: Started restoring cached build plugins
2:26:34 PM: Finished restoring cached build plugins
2:26:35 PM: Attempting ruby version 2.6.2, read from environment
2:26:36 PM: Using ruby version 2.6.2
2:26:36 PM: Using PHP version 5.6
2:26:36 PM: Started restoring cached go cache
2:26:36 PM: Finished restoring cached go cache
2:26:36 PM: Installing Go version 1.12
2:26:42 PM: unset GOOS;
2:26:42 PM: unset GOARCH;
2:26:42 PM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64';
2:26:42 PM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:${PATH}";
2:26:42 PM: go version >&2;
2:26:42 PM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env"
2:26:42 PM: go version go1.12 linux/amd64
2:26:42 PM: Installing missing commands
2:26:42 PM: Verify run directory
2:26:44 PM: ​
2:26:44 PM: ────────────────────────────────────────────────────────────────
2:26:44 PM:   Netlify Build                                                 
2:26:44 PM: ────────────────────────────────────────────────────────────────
2:26:44 PM: ​
2:26:44 PM: ❯ Version
2:26:44 PM:   @netlify/build 27.3.3
2:26:44 PM: ​
2:26:44 PM: ❯ Flags
2:26:44 PM:   baseRelDir: false
2:26:44 PM:   buildId: 62c876d3f399775bf0da191a
2:26:44 PM:   deployId: 62c876d3f399775bf0da191c
2:26:44 PM: ​
2:26:44 PM: ❯ Current directory
2:26:44 PM:   /opt/build/repo
2:26:44 PM: ​
2:26:44 PM: ❯ Config file
2:26:44 PM:   No config file was defined: using default values.
2:26:44 PM: ​
2:26:44 PM: ❯ Context
2:26:44 PM:   production
2:26:44 PM: ​
2:26:44 PM: ────────────────────────────────────────────────────────────────
2:26:44 PM:   1. Build command from Netlify app                             
2:26:44 PM: ────────────────────────────────────────────────────────────────
2:26:44 PM: ​
2:26:44 PM: $ npm run build
2:26:44 PM: npm ERR! code ENOENT
2:26:44 PM: npm ERR! syscall open
2:26:44 PM: npm ERR! path /opt/build/repo/package.json
2:26:44 PM: npm ERR! errno -2
2:26:44 PM: npm ERR! enoent ENOENT: no such file or directory, open '/opt/build/repo/package.json'
2:26:44 PM: npm ERR! enoent This is related to npm not being able to find a file.
2:26:44 PM: npm ERR! enoent
2:26:44 PM: npm ERR! A complete log of this run can be found in:
2:26:44 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-07-08T18_26_44_534Z-debug.log
2:26:44 PM: ​
2:26:44 PM: ────────────────────────────────────────────────────────────────
2:26:44 PM:   "build.command" failed                                        
2:26:44 PM: ────────────────────────────────────────────────────────────────
2:26:44 PM: ​
2:26:44 PM:   Error message
2:26:44 PM:   Command failed with exit code 254: npm run build (https://ntl.fyi/exit-code-254)
2:26:44 PM: ​
2:26:44 PM:   Error location
2:26:44 PM:   In Build command from Netlify app:
2:26:44 PM:   npm run build
2:26:44 PM: ​
2:26:44 PM:   Resolved config
2:26:44 PM:   build:
2:26:44 PM:     command: npm run build
2:26:44 PM:     commandOrigin: ui
2:26:44 PM:     publish: /opt/build/repo/dist
2:26:44 PM:     publishOrigin: ui
2:26:44 PM: Caching artifacts
2:26:44 PM: Started saving build plugins
2:26:44 PM: Finished saving build plugins
2:26:44 PM: Started saving pip cache
2:26:45 PM: Finished saving pip cache
2:26:45 PM: Started saving emacs cask dependencies
2:26:45 PM: Finished saving emacs cask dependencies
2:26:45 PM: Started saving maven dependencies
2:26:45 PM: Finished saving maven dependencies
2:26:45 PM: Started saving boot dependencies
2:26:45 PM: Finished saving boot dependencies
2:26:45 PM: Started saving rust rustup cache
2:26:45 PM: Finished saving rust rustup cache
2:26:45 PM: Started saving go dependencies
2:26:46 PM: Finished saving go dependencies
2:26:48 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:26:48 PM: Creating deploy upload records
2:26:49 PM: Failing build: Failed to build site
2:26:49 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
2:26:50 PM: Finished processing build request in 21.047654624s

Thanks for any troubleshooting or help you can offer

Update

Okay, so I ran with the build command ls just confirm I was getting the right directory contents, and it looks like I’m pointed to the wrong repo

I updated the repo and fixed my issue!