ENOENT: no such file or directory, open '/opt/build/repo/package.json'

Our site builds in development, but fails in production.

The error seems to be here: ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’

Not sure why production is failing to build. Can you help?

Netlify site name: goodhere.netlify.app

Github repo: https://github.com/benrmatthews/goodhere

Build Log:

3:59:34 PM: Build ready to start
3:59:36 PM: build-image version: 30f629161c0736b1a3ecd8b418e5eeffab5c0faf
3:59:36 PM: build-image tag: v3.3.14
3:59:36 PM: buildbot version: 1da4cf38e1ad1fe9ce7deeeba939bcc9c6c3f794
3:59:37 PM: Fetching cached dependencies
3:59:37 PM: Starting to download cache of 1.4GB
4:00:09 PM: Finished downloading cache in 32.533439707s
4:00:09 PM: Starting to extract cache
4:00:50 PM: Finished extracting cache in 40.215063027s
4:00:50 PM: Finished fetching cache in 1m13.1005571s
4:00:50 PM: Starting to prepare the repo for build
4:00:50 PM: Preparing Git Reference refs/heads/master
4:01:26 PM: Starting build script
4:01:26 PM: Installing dependencies
4:01:27 PM: Started restoring cached node version
4:01:30 PM: Finished restoring cached node version
4:01:30 PM: v10.20.1 is already installed.
4:01:31 PM: Now using node v10.20.1 (npm v6.14.4)
4:01:31 PM: Started restoring cached build plugins
4:01:31 PM: Finished restoring cached build plugins
4:01:31 PM: Attempting ruby version 2.6.2, read from environment
4:01:33 PM: Using ruby version 2.6.2
4:01:33 PM: Using PHP version 5.6
4:01:33 PM: 5.2 is already installed.
4:01:33 PM: Using Swift version 5.2
4:01:33 PM: Started restoring cached go cache
4:01:33 PM: Finished restoring cached go cache
4:01:33 PM: go version go1.12 linux/amd64
4:01:33 PM: go version go1.12 linux/amd64
4:01:33 PM: Installing missing commands
4:01:33 PM: Verify run directory
4:01:35 PM: ​
4:01:35 PM: ┌─────────────────────────────┐
4:01:35 PM: │        Netlify Build        │
4:01:35 PM: └─────────────────────────────┘
4:01:35 PM: ​
4:01:35 PM: ❯ Version
4:01:35 PM:   @netlify/build 1.0.10
4:01:35 PM: ​
4:01:35 PM: ❯ Flags
4:01:35 PM:   mode: buildbot
4:01:35 PM: ​
4:01:35 PM: ❯ Current directory
4:01:35 PM:   /opt/build/repo
4:01:35 PM: ​
4:01:35 PM: ❯ Config file
4:01:35 PM:   No config file was defined: using default values.
4:01:35 PM: ​
4:01:35 PM: ❯ Context
4:01:35 PM:   production
4:01:35 PM: ​
4:01:35 PM: ┌────────────────────────────────┐
4:01:35 PM: │ 1. Build command from settings │
4:01:35 PM: └────────────────────────────────┘
4:01:35 PM: ​
4:01:35 PM: $ npm run build
4:01:36 PM: npm
4:01:36 PM: ERR!
4:01:36 PM:  code ENOENT
4:01:36 PM: npm
4:01:36 PM:  ERR! syscall
4:01:36 PM:  open
4:01:36 PM: npm
4:01:36 PM: ERR!
4:01:36 PM: path
4:01:36 PM:  /opt/build/repo/package.json
4:01:36 PM: npm
4:01:36 PM:  ERR!
4:01:36 PM: errno -2
4:01:36 PM: npm
4:01:36 PM:  ERR! enoent
4:01:36 PM:  ENOENT: no such file or directory, open '/opt/build/repo/package.json'
4:01:36 PM: npm
4:01:36 PM:  ERR! enoent
4:01:36 PM:  This is related to npm not being able to find a file.
4:01:36 PM: npm
4:01:36 PM: ERR!
4:01:36 PM: enoent
4:01:36 PM: npm ERR!
4:01:36 PM:  A complete log of this run can be found in:
4:01:36 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-05-28T15_01_36_121Z-debug.log
4:01:36 PM: ​
4:01:36 PM: ┌─────────────────────────────┐
4:01:36 PM: │   "build.command" failed    │
4:01:36 PM: └─────────────────────────────┘
4:01:36 PM: ​
4:01:36 PM:   Error message
4:01:36 PM:   Command failed with exit code 254: npm run build
4:01:36 PM: ​
4:01:36 PM:   Error location
4:01:36 PM:   In Build command from settings:
4:01:36 PM:   npm run build
4:01:36 PM: ​
4:01:36 PM:   Resolved config
4:01:36 PM:   build:
4:01:36 PM:     command: npm run build
4:01:36 PM:     publish: /opt/build/repo/public
4:01:36 PM: Caching artifacts
4:01:36 PM: Started saving build plugins
4:01:36 PM: Finished saving build plugins
4:01:36 PM: Started saving pip cache
4:01:37 PM: Finished saving pip cache
4:01:37 PM: Started saving emacs cask dependencies
4:01:38 PM: Finished saving emacs cask dependencies
4:01:38 PM: Started saving maven dependencies
4:01:38 PM: Finished saving maven dependencies
4:01:38 PM: Started saving boot dependencies
4:01:38 PM: Finished saving boot dependencies
4:01:38 PM: Started saving go dependencies
4:01:38 PM: Finished saving go dependencies
4:01:38 PM: Error running command: Build script returned non-zero exit code: 1
4:01:38 PM: Failing build: Failed to build site
4:01:38 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1
4:01:38 PM: Finished processing build request in 2m1.895022637s

The builder is looking for package.json at the root of your repo and not finding it.

In your Netlify site build settings, you should set the base directory to the directory that contains your package.json file. Looking at your repo, it should probably be goodhere/site.

I think you will also need to update your publish directory to be goodhere/site/public.

1 Like

Thanks @william - that fixed the issue! We were referencing /site, not goodhere/site. Changing the base fixed it.

1 Like