Failed during stage 'building site': Build script returned non-zero exit code: 2 (

I’m trying to deploy a React Js App I saved on a Git Hub repo. But, when I start the deploy I get hit with the error: My Build Failed during stage ‘building site’: Build script returned non-zero exit code: 2. Also, when I build the React Js app locally, it builds successfully, for some reason it is just not deploying!

My Deploy log is shown below:

8:28:37 PM: build-image version: a2d22d22e4555d1ef0a972ed14a0a4b366ad20c4 (focal)
8:28:37 PM: build-image tag: v4.16.3
8:28:37 PM: buildbot version: 3bd65547ad0cc7e555b4d091bb1e3da5ef545973
8:28:37 PM: Fetching cached dependencies
8:28:37 PM: Failed to fetch cache, continuing with build
8:28:37 PM: Starting to prepare the repo for build
8:28:37 PM: No cached dependencies found. Cloning fresh repo
8:28:37 PM: git clone --filter=blob:none
8:29:03 PM: Preparing Git Reference refs/heads/main
8:29:04 PM: Parsing package.json dependencies
8:29:05 PM: Starting build script
8:29:06 PM: Installing dependencies
8:29:06 PM: Python version set to 2.7
8:29:06 PM: v16.19.0 is already installed.
8:29:06 PM: Now using node v16.19.0 (npm v8.19.3)
8:29:06 PM: Enabling Node.js Corepack
8:29:07 PM: Started restoring cached build plugins
8:29:07 PM: Finished restoring cached build plugins
8:29:07 PM: Attempting Ruby version 2.7.2, read from environment
8:29:08 PM: Using Ruby version 2.7.2
8:29:08 PM: Using PHP version 8.0
8:29:08 PM: Started restoring cached corepack dependencies
8:29:08 PM: mv: cannot move ‘/opt/build/cache/.node/corepack’ to ‘/opt/buildhome/.node/corepack’: No such file or directory
8:29:08 PM: Finished restoring cached corepack dependencies
8:29:08 PM: No npm workspaces detected
8:29:08 PM: Started restoring cached node modules
8:29:08 PM: Finished restoring cached node modules
8:29:08 PM: Bypassing sha validation. Running pre & post install scripts
8:29:08 PM: Installing npm packages using npm version 8.19.3
8:29:13 PM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform’s native and performance.timeOrigin.npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: Array.prototype.sort() - JavaScript | MDN
8:29:13 PM: npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
8:29:13 PM: npm WARN deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
8:29:16 PM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
8:29:27 PM: added 1514 packages, and audited 1515 packages in 19s
8:29:27 PM: 235 packages are looking for funding
8:29:27 PM: run npm fund for details
8:29:27 PM: 7 high severity vulnerabilities
8:29:27 PM: To address issues that do not require attention, run:
8:29:27 PM: npm audit fix
8:29:27 PM: To address all issues (including breaking changes), run:
8:29:27 PM: npm audit fix --force
8:29:27 PM: Run npm audit for details.
8:29:27 PM: npm packages installed
8:29:28 PM: Started restoring cached go cache
8:29:28 PM: Finished restoring cached go cache
8:29:29 PM: Installing Go version 1.19.5 (requested 1.19.x)
8:29:34 PM: unset GOOS;
8:29:34 PM: unset GOARCH;
8:29:34 PM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.19.5.linux.amd64’;
8:29:34 PM: export PATH=“/opt/buildhome/.gimme/versions/go1.19.5.linux.amd64/bin:${PATH}”;
8:29:34 PM: go version >&2;
8:29:34 PM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.19.5.linux.amd64.env”
8:29:34 PM: go version go1.19.5 linux/amd64
8:29:35 PM: Detected 1 framework(s)
8:29:35 PM: “create-react-app” at version “5.0.1”
8:29:35 PM: Installing missing commands
8:29:35 PM: Verify run directory
8:29:35 PM: Section completed: initializing
8:29:36 PM: ​
8:29:36 PM: Netlify Build
8:29:36 PM: ────────────────────────────────────────────────────────────────
8:29:36 PM: ​
8:29:36 PM: ❯ Version
8:29:36 PM: @netlify/build 29.5.0
8:29:36 PM: ​
8:29:36 PM: ❯ Flags
8:29:36 PM: baseRelDir: true
8:29:36 PM: buildId: 63c74b43ae0c7e6f7e47902d
8:29:36 PM: deployId: 63c74b43ae0c7e6f7e47902f
8:29:36 PM: ​
8:29:36 PM: ❯ Current directory
8:29:36 PM: /opt/build/repo
8:29:36 PM: ​
8:29:36 PM: ❯ Config file
8:29:36 PM: No config file was defined: using default values.
8:29:36 PM: ​
8:29:36 PM: ❯ Context
8:29:36 PM: production
8:29:36 PM: ​
8:29:36 PM: 1. Build command from Netlify app
8:29:36 PM: ────────────────────────────────────────────────────────────────
8:29:36 PM: ​
8:29:36 PM: $ npm run build
8:29:37 PM: > farm2clinic@0.1.0 build
8:29:37 PM: > react-scripts build
8:29:38 PM: Creating an optimized production build…
8:30:05 PM:
8:30:05 PM: Treating warnings as errors because process.env.CI = true.
8:30:05 PM: Most CI servers set it automatically.
8:30:05 PM:
8:30:05 PM: Failed to compile.
8:30:05 PM:
8:30:05 PM: [eslint]
8:30:05 PM: src/Helper/SpanishData.js
8:30:05 PM: Line 1:8: ‘React’ is defined but never used no-unused-vars
8:30:05 PM: src/pages/GetInvolved.js
8:30:05 PM: Line 104:11:

Hi @jethrolibutan :wave:t6: ,

I am not sure if this is right , but have you given the following a try:

  • Specify base directory OR
  • create netlify.toml in project directory?

Also please give this support guide a read and see if this helps? [Support Guide] Compiled Build and Deploy Resources -- start here!

Hi, I’m having the same issue and referred to the docs for more information. Commenting to receive any updates if they occur.
All solutions suggested in the docs and forums (update dependencies, add CLI=false ENV, add Netlify debugger, making sure build command works, etc.) haven’t worked for me. I get all the way to the end of the build process without error then get exit code 2. My repo builds just fine in my local environment, and deploys. Not sure where the bug is, unless some things just aren’t playing nice.

Which site on your account is this happening so we can investigate?

I was receiving this error too recently on serene-feynman-d5863c
i note you probably mean “CI=false” instead of “CLI=false” for the environment variable.

For me, either adding "CI= " to my build command or setting the NODE_VERSION appears to have finally resolved this for me in netlify.toml

command = “CI= npm run prod”
publish = “build_production”
environment = { PHP_VERSION = “8.1”, NODE_VERSION = “18.16.0”}

thanks for sharing this with the community!