Cant build website for Docusaurus to Netflfy: Failed during stage 'building site': Build script returned non-zero exit code: 2

Hi,

I’m trying a POC with Docusaurus and sending the build to Netlify. I have been able to build locally without any problem.

I set the parameters when creating my deployment like this:

Here is my deployment log:

Deploy log

2:53:26 PM: Build ready to start
2:53:27 PM: build-image version: 4c0c1cadee6a31c9bb8d824514030009c4c05c6a (focal)
2:53:27 PM: build-image tag: v4.15.0
2:53:27 PM: buildbot version: 44377b3b6a4027dd8a09c3df7d29646ce9192423
2:53:27 PM: Fetching cached dependencies
2:53:27 PM: Failed to fetch cache, continuing with build
2:53:27 PM: Starting to prepare the repo for build
2:53:27 PM: No cached dependencies found. Cloning fresh repo
2:53:27 PM: git clone git@bitbucket.org:russ1/master
2:53:28 PM: Preparing Git Reference refs/heads/OM_Netlify_POC
2:53:29 PM: Parsing package.json dependencies
2:53:29 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: ‘’ versus ‘/’ in the Netlify UI
2:53:29 PM: Section completed: initializing
2:53:30 PM: Starting build script
2:53:30 PM: Installing dependencies
2:53:30 PM: Python version set to 2.7
2:53:30 PM: v16.18.1 is already installed.
2:53:30 PM: Now using node v16.18.1 (npm v8.19.2)
2:53:30 PM: Enabling node corepack
2:53:31 PM: Started restoring cached build plugins
2:53:31 PM: Finished restoring cached build plugins
2:53:31 PM: Attempting ruby version 2.7.2, read from environment
2:53:31 PM: Using ruby version 2.7.2
2:53:31 PM: Using PHP version 8.0
2:53:31 PM: Started restoring cached go cache
2:53:31 PM: Finished restoring cached go cache
2:53:32 PM: Installing Go version 1.19.3 (requested 1.19.x)
2:53:37 PM: unset GOOS;
2:53:37 PM: unset GOARCH;
2:53:37 PM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.19.3.linux.amd64’;
2:53:37 PM: export PATH=“/opt/buildhome/.gimme/versions/go1.19.3.linux.amd64/bin:${PATH}”;
2:53:37 PM: go version >&2;
2:53:37 PM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.19.3.linux.amd64.env”
2:53:37 PM: go version go1.19.3 linux/amd64
2:53:37 PM: Detected 0 framework(s)
2:53:37 PM: Installing missing commands
2:53:37 PM: Verify run directory
2:53:39 PM: ​
2:53:39 PM: ────────────────────────────────────────────────────────────────
2:53:39 PM: Netlify Build
2:53:39 PM: ────────────────────────────────────────────────────────────────
2:53:39 PM: ​
2:53:39 PM: ❯ Version
2:53:39 PM: @netlify/build 28.4.0
2:53:39 PM: ​
2:53:39 PM: ❯ Flags
2:53:39 PM: baseRelDir: true
2:53:39 PM: buildId: 637e8846acf33a4ec6a9c2f2
2:53:39 PM: deployId: 637e8846acf33a4ec6a9c2f4
2:53:39 PM: ​
2:53:39 PM: ❯ Current directory
2:53:39 PM: /opt/build/repo
2:53:39 PM: ​
2:53:39 PM: ❯ Config file
2:53:39 PM: No config file was defined: using default values.
2:53:39 PM: ​
2:53:39 PM: ❯ Context
2:53:39 PM: production
2:53:39 PM: ​
2:53:39 PM: ────────────────────────────────────────────────────────────────
2:53:39 PM: 1. Build command from Netlify app
2:53:39 PM: ────────────────────────────────────────────────────────────────
2:53:39 PM: ​
2:53:39 PM: $ npm run build
2:53:39 PM: npm ERR! code ENOENT
2:53:39 PM: npm ERR! syscall open
2:53:39 PM: npm ERR! path /opt/build/repo/package.json
2:53:39 PM: npm ERR! errno -2
2:53:39 PM: npm ERR! enoent ENOENT: no such file or directory, open ‘/opt/build/repo/package.json’
2:53:39 PM: npm ERR! enoent This is related to npm not being able to find a file.
2:53:39 PM: npm ERR! enoent
2:53:39 PM: npm ERR! A complete log of this run can be found in:
2:53:39 PM: npm ERR! /opt/buildhome/.npm/_logs/2022-11-23T20_53_39_544Z-debug-0.log
2:53:39 PM: ​
2:53:40 PM: Creating deploy upload records
2:53:39 PM: ────────────────────────────────────────────────────────────────
2:53:39 PM: “build.command” failed
2:53:39 PM: ────────────────────────────────────────────────────────────────
2:53:39 PM: ​
2:53:39 PM: Error message
2:53:40 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)
2:53:39 PM: Command failed with exit code 254: npm run build (Search results for '"non-zero exit code: 254"' - Netlify Support Forums)
2:53:39 PM: ​
2:53:39 PM: Error location
2:53:39 PM: In Build command from Netlify app:
2:53:39 PM: npm run build
2:53:39 PM: ​
2:53:39 PM: Resolved config
2:53:39 PM: build:
2:53:39 PM: base: /opt/build/repo
2:53:39 PM: command: npm run build
2:53:39 PM: commandOrigin: ui
2:53:39 PM: publish: /opt/build/repo/build
2:53:39 PM: publishOrigin: ui
2:53:40 PM: Caching artifacts
2:53:40 PM: Started saving build plugins
2:53:40 PM: Finished saving build plugins
2:53:40 PM: Started saving pip cache
2:53:40 PM: Finished saving pip cache
2:53:40 PM: Started saving emacs cask dependencies
2:53:40 PM: Finished saving emacs cask dependencies
2:53:40 PM: Started saving maven dependencies
2:53:40 PM: Finished saving maven dependencies
2:53:40 PM: Started saving boot dependencies
2:53:40 PM: Finished saving boot dependencies
2:53:40 PM: Started saving rust rustup cache
2:53:40 PM: Finished saving rust rustup cache
2:53:40 PM: Started saving go dependencies
2:53:40 PM: Finished saving go dependencies
2:53:40 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:53:40 PM: Failing build: Failed to build site
2:53:41 PM: Finished processing build request in 13.701072704s

any help is greatly appreciated! Thanks so much!

Russ

Fixed on my end, needed to enter correct base directory wrt the remote repo.

Thanks,

Russ

Hi @russ.urquhart :wave:t6: ! Welcome to the forums. We are so glad you’re here :smiling_face_with_three_hearts:. I am glad to hear you were able to resolve this issue on your own. Thanks for coming back and letting us know what worked. This will really help other forums user who encounter similar problems in the future. Happy building and thanks for making the community great! :netliconfetti: