Unable to build a website from Github repository

Hello,

I have tried most of the suggestions about this error codes: Command failed with exit code 127: npm run build and Failed during stage ‘building site’: Build script returned non-zero exit code: 2, but I can’t seem to make it work.
I tried changing the build command to CI= npm run build, only build, webpack, etc.
I added the CI false variable. No change. I don’t see where exactly is the problem, because there is no ERR message, please check the log below.

Issue building below:

12:05:07 PM: Build ready to start
12:05:31 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
12:05:31 PM: build-image tag: v4.10.1
12:05:31 PM: buildbot version: 4cffa5dc84445a450e8be6f710e2498d87994fae
12:05:31 PM: Fetching cached dependencies
12:05:31 PM: Failed to fetch cache, continuing with build
12:05:31 PM: Starting to prepare the repo for build
12:05:31 PM: No cached dependencies found. Cloning fresh repo
12:05:31 PM: git clone https://github.com/vivka7/travel-site
12:05:31 PM: Preparing Git Reference refs/heads/master
12:05:32 PM: Parsing package.json dependencies
12:05:32 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: ‘docs’ versus ‘’ in the Netlify UI
12:05:32 PM: Starting build script
12:05:32 PM: Installing dependencies
12:05:32 PM: Python version set to 2.7
12:05:33 PM: Downloading and installing node v16.17.0…
12:05:33 PM: Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz
12:05:33 PM: Computing checksum with sha256sum
12:05:33 PM: Checksums matched!
12:05:35 PM: Now using node v16.17.0 (npm v8.15.0)
12:05:35 PM: Started restoring cached build plugins
12:05:35 PM: Finished restoring cached build plugins
12:05:35 PM: Attempting ruby version 2.7.2, read from environment
12:05:36 PM: Using ruby version 2.7.2
12:05:36 PM: Using PHP version 8.0
12:05:36 PM: Started restoring cached go cache
12:05:36 PM: Finished restoring cached go cache
12:05:36 PM: Installing Go version 1.17 (requested 1.17)
12:05:42 PM: unset GOOS;
12:05:42 PM: unset GOARCH;
12:05:42 PM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.17.linux.amd64’;
12:05:42 PM: export PATH=“/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}”;
12:05:42 PM: go version >&2;
12:05:42 PM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.17.linux.amd64.env”
12:05:42 PM: go version go1.17 linux/amd64
12:05:42 PM: Installing missing commands
12:05:42 PM: Verify run directory
12:05:43 PM: ​
12:05:43 PM: ────────────────────────────────────────────────────────────────
12:05:43 PM: Netlify Build
12:05:43 PM: ────────────────────────────────────────────────────────────────
12:05:43 PM: ​
12:05:43 PM: ❯ Version
12:05:43 PM: @netlify/build 27.11.5
12:05:43 PM: ​
12:05:43 PM: ❯ Flags
12:05:43 PM: baseRelDir: true
12:05:43 PM: buildId: 62fe00c374218e00b22660df
12:05:43 PM: deployId: 62fe00c374218e00b22660e1
12:05:43 PM: ​
12:05:43 PM: ❯ Current directory
12:05:43 PM: /opt/build/repo/docs
12:05:43 PM: ​
12:05:43 PM: ❯ Config file
12:05:43 PM: No config file was defined: using default values.
12:05:43 PM: ​
12:05:43 PM: ❯ Context
12:05:43 PM: production
12:05:43 PM: ​
12:05:43 PM: ────────────────────────────────────────────────────────────────
12:05:43 PM: 1. Build command from Netlify app
12:05:43 PM: ────────────────────────────────────────────────────────────────
12:05:43 PM: ​
12:05:43 PM: $ npm run build
12:05:43 PM: > test-repo@1.0.0 build
12:05:43 PM: > webpack
12:05:43 PM: /tmp/build-032cadb6.sh: 1: webpack: not found
12:05:43 PM: ​
12:05:43 PM: ────────────────────────────────────────────────────────────────
12:05:43 PM: “build.command” failed
12:05:43 PM: ────────────────────────────────────────────────────────────────
12:05:43 PM: ​
12:05:43 PM: Error message
12:05:43 PM: Command failed with exit code 127: npm run build (Search results for '"non-zero exit code: 127"' - Netlify Support Forums)
12:05:43 PM: ​
12:05:43 PM: Error location
12:05:45 PM: Creating deploy upload records
12:05:43 PM: In Build command from Netlify app:
12:05:43 PM: npm run build
12:05:43 PM: ​
12:05:43 PM: Resolved config
12:05:45 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
12:05:43 PM: build:
12:05:43 PM: base: /opt/build/repo/docs
12:05:43 PM: command: npm run build
12:05:43 PM: commandOrigin: ui
12:05:43 PM: environment:
12:05:43 PM: - CI
12:05:43 PM: publish: /opt/build/repo/docs
12:05:43 PM: publishOrigin: default
12:05:44 PM: Caching artifacts
12:05:44 PM: Started saving build plugins
12:05:44 PM: Finished saving build plugins
12:05:44 PM: Started saving pip cache
12:05:44 PM: Finished saving pip cache
12:05:44 PM: Started saving emacs cask dependencies
12:05:44 PM: Finished saving emacs cask dependencies
12:05:44 PM: Started saving maven dependencies
12:05:44 PM: Finished saving maven dependencies
12:05:44 PM: Started saving boot dependencies
12:05:44 PM: Finished saving boot dependencies
12:05:44 PM: Started saving rust rustup cache
12:05:44 PM: Finished saving rust rustup cache
12:05:44 PM: Started saving go dependencies
12:05:44 PM: Finished saving go dependencies
12:05:45 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:05:45 PM: Failing build: Failed to build site
12:05:45 PM: Finished processing build request in 14.35767889s

PS. The website in Github is running and works: https://vivka7.github.io/travel-site/

Thank you in advance!

Hi @vivka7

It would appear the docs directory contains a built site that requires no building, therefore there is no need for a build step. Set the publish directory to docs and the site should deploy without issue.

1 Like

OMG thank you!
Just removed the build command and it worked!

1 Like

Hey there, @vivka7 :wave: glad everything is working for you now! Happy building :rocket:

1 Like