Deploying Updated React App

I have a project that is supposed to be on automatic deployments when I push changes to it from the repository on github but keep getting the following error message:

2:57:37 PM: 1. Build command from Netlify app
2:57:37 PM: ────────────────────────────────────────────────────────────────
2:57:37 PM: ​
2:57:37 PM: $ CI= npm run build
2:57:37 PM: npm ERR! code ENOENT
2:57:37 PM: npm ERR! syscall open
2:57:37 PM: npm ERR! path /opt/build/repo/package.json
2:57:37 PM: npm ERR! errno -2
2:57:37 PM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
2:57:37 PM: npm ERR! enoent This is related to npm not being able to find a file.
2:57:37 PM: npm ERR! enoent
2:57:37 PM: npm ERR! A complete log of this run can be found in:
2:57:37 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-11-28T22_57_37_886Z-debug.log
2:57:37 PM: ​
2:57:37 PM: ────────────────────────────────────────────────────────────────
2:57:37 PM: “build.command” failed
2:57:37 PM: ────────────────────────────────────────────────────────────────
2:57:37 PM: ​
2:57:37 PM: Error message
2:57:37 PM: Command failed with exit code 254: CI= npm run build
2:57:37 PM: ​
2:57:37 PM: Error location
2:57:37 PM: In Build command from Netlify app:
2:57:37 PM: CI= npm run build
2:57:37 PM: ​
2:57:37 PM: Resolved config
2:57:37 PM: build:
2:57:37 PM: command: CI= npm run build
2:57:37 PM: commandOrigin: ui
2:57:37 PM: publish: /opt/build/repo/build
2:57:38 PM: Caching artifacts
2:57:38 PM: Started saving build plugins
2:57:38 PM: Finished saving build plugins
2:57:38 PM: Started saving pip cache
2:57:38 PM: Finished saving pip cache
2:57:38 PM: Started saving emacs cask dependencies
2:57:38 PM: Finished saving emacs cask dependencies
2:57:38 PM: Started saving maven dependencies
2:57:38 PM: Finished saving maven dependencies
2:57:38 PM: Started saving boot dependencies
2:57:38 PM: Finished saving boot dependencies
2:57:38 PM: Started saving go dependencies
2:57:38 PM: Finished saving go dependencies
2:57:40 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:57:40 PM: Failing build: Failed to build site
2:57:40 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2

I noticed this error has happened even after I was able to successfully deploy it with automatic deployments initially.

It shows the error. There’s no package.json. Recheck if you have one in your repo.

1 Like

I have a package json. What does it need to have?

It would need to be in the root of your repository if you don’t set a base directory. Otherwise, it needs to be in the base directory if you set it.

Our system is not finding it, hence that error message.

In the build settings, would I set the base directory to main, since it is the root directory?

The base directory should be the same one that has your package.json

I changed the base directory to portfolio, which is where I wanted to build the site from, but got the same message as before.

Do you mind sharing the repo so we can have a better look at what’s happening?

I can definitely do that.