Home
Support Forums

Build command fails - error

I need advice to debug deploy https://app.netlify.com/sites/festive-albattani-f53ea2/deploys/5fbd9609f24cc500d867f123 - here is relevant part of the log:

  build:
6:24:03 PM:     command: 'npm run docs:build'
6:24:03 PM:     commandOrigin: ui
6:24:03 PM:     publish: /opt/build/repo/.vuepress/dist
6:24:03 PM: Caching artifacts
6:24:03 PM: Started saving build plugins
6:24:03 PM: Finished saving build plugins
6:24:03 PM: Started saving pip cache
6:24:04 PM: Finished saving pip cache
6:24:04 PM: Started saving emacs cask dependencies
6:24:04 PM: Finished saving emacs cask dependencies
6:24:04 PM: Started saving maven dependencies
6:24:04 PM: Finished saving maven dependencies
6:24:04 PM: Started saving boot dependencies
6:24:04 PM: Finished saving boot dependencies
6:24:04 PM: Started saving go dependencies
6:24:04 PM: Finished saving go dependencies
6:24:06 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:24:06 PM: Failing build: Failed to build site
6:24:06 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
6:24:06 PM: Finished processing build request in 11.601973575s

Hi, @adriatic. This is a screenshot of the repo at this time:

This repo only has a single file named README.md. The use of npm run requires that there be a package.json file in this repository. Because this file is missing the npm command returns this error:

3:24:03 PM: $ npm run docs:build
3:24:03 PM: npm ERR! code ENOENT
3:24:03 PM: npm ERR! syscall open
3:24:03 PM: npm ERR! path /opt/build/repo/package.json
3:24:03 PM: npm ERR! errno -2
3:24:03 PM: npm ERR! enoent ENOENT: no such file or directory, open '/opt/build/repo/package.json'
3:24:03 PM: npm ERR! enoent This is related to npm not being able to find a file.
3:24:03 PM: npm ERR! enoent
3:24:03 PM: npm ERR! A complete log of this run can be found in:
3:24:03 PM: npm ERR!     /opt/buildhome/.npm/_logs/2020-11-24T23_24_03_709Z-debug.log

The error above is npm saying in other words, “I cannot find your package.json file.” This is the log line which says that (again, using other words):

3:24:03 PM: npm ERR! enoent ENOENT: no such file or directory, open '/opt/build/repo/package.json'

Do you have a package.json locally? If so, you will need to commit that file (and many other files) to this repository before the builds will be successful using this repo.

If there are other questions or concerns, please let us know.

Many thanks @luke - this is the best response I ever encountered. It’s informative and complete. My case is slightly more complicated than simply forgetting to create the package.json file, somehow Git created two branches of the repo, and the build process fetched the wrong one.

1 Like

Hi, @adriatic. There is a site setting to chose which branch to use for a site’s repository. A site can even build all branches for a repo (or just some subset of branches that you select). One branch is always the “production” branch and the other branches make “branch deploys” versions of the site where the branch name is prefixed to the site subdomain with two dashes (--) between them.

For example, if the branch is staging and the site subdomain is example then the branch deploy URL would be https://staging--example.netlify.app/.

Thank you for letting me know my response was helpful and I’m glad to learn it was something as simple as the wrong branch being used by default.

Thank you for telling me how Netlify “handles” multiple branches. My initial approach was silly - trying to follow a two years old tutorial describing the deployment process to Netlify - information that has changed a lot (for better). I will now follow your official guide to relearn Netlify deployment correctly emoticon_wink.png