Build script returned non-zero exit code: 2 - I added logos and broke it

To be honest, I don’t know what is going on, everything was working a few days ago. When I added a GitHub and LinkedIn logo and added a lib to do so, I started getting dependency issues. Then someone shared this link (Deploy failed today: Build was terminated: Build script returned non-zero exit code: 1 - #2 by nathanmartin) with me to help my solve it, but despite setting the NPM_FLAGS to legacy-per-deps or force, neither worked for me.

Could someone please help me?

5:18:17 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
5:18:17 PM: build-image tag: v4.14.3
5:18:17 PM: buildbot version: f2613f2234a773b4fab58b5a3c03c743fe78f9bf
5:18:17 PM: Fetching cached dependencies
5:18:17 PM: Starting to download cache of 121.4MB
5:18:19 PM: Finished downloading cache in 2.699966717s
5:18:19 PM: Starting to extract cache
5:18:21 PM: Finished extracting cache in 1.207473274s
5:18:21 PM: Finished fetching cache in 3.951607873s
5:18:21 PM: Starting to prepare the repo for build
5:18:21 PM: Preparing Git Reference refs/heads/main
5:18:22 PM: Parsing package.json dependencies
5:18:23 PM: Different build command detected, going to use the one specified in the Netlify configuration file: ‘CI= npm run build’ versus ‘yarn run build’ in the Netlify UI
5:18:23 PM: Starting build script
5:18:23 PM: Installing dependencies
5:18:23 PM: Python version set to 2.7
5:18:23 PM: Started restoring cached node version
5:18:24 PM: Finished restoring cached node version
5:18:24 PM: v16.18.0 is already installed.
5:18:25 PM: Now using node v16.18.0 (npm v8.19.2)
5:18:25 PM: Enabling node corepack
5:18:25 PM: Started restoring cached build plugins
5:18:25 PM: Finished restoring cached build plugins
5:18:25 PM: Attempting ruby version 2.7.2, read from environment
5:18:26 PM: Using ruby version 2.7.2
5:18:26 PM: Using PHP version 8.0
5:18:26 PM: No npm workspaces detected
5:18:26 PM: Started restoring cached node modules
5:18:26 PM: Finished restoring cached node modules
5:18:26 PM: Installing NPM modules using NPM version 8.19.2
5:18:32 PM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform’s native performance.now() 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
5:18:34 PM: npm WARN deprecated uglify-es@3.3.9: support for ECMAScript is superseded by uglify-js as of v3.13.0
5:18:37 PM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
5:18:44 PM: added 1394 packages, removed 1004 packages, changed 333 packages, and audited 2114 packages in 17s
5:18:44 PM: 231 packages are looking for funding
5:18:44 PM: run npm fund for details
5:18:44 PM: 9 vulnerabilities (3 moderate, 6 high)
5:18:44 PM: To address all issues possible (including breaking changes), run:
5:18:44 PM: npm audit fix --force
5:18:44 PM: Some issues need review, and may require choosing
5:18:44 PM: a different dependency.
5:18:44 PM: Run npm audit for details.
5:18:44 PM: NPM modules installed
5:18:44 PM: Creating package sha
5:18:44 PM: Started restoring cached go cache
5:18:44 PM: Finished restoring cached go cache
5:18:44 PM: Installing Go version 1.17 (requested 1.17)
5:18:48 PM: unset GOOS;
5:18:48 PM: unset GOARCH;
5:18:48 PM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.17.linux.amd64’;
5:18:48 PM: export PATH=“/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}”;
5:18:48 PM: go version >&2;
5:18:48 PM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.17.linux.amd64.env”
5:18:48 PM: go version go1.17 linux/amd64
5:18:49 PM: Installing missing commands
5:18:49 PM: Verify run directory
5:18:50 PM: ​
5:18:50 PM: ────────────────────────────────────────────────────────────────
5:18:50 PM: Netlify Build
5:18:50 PM: ────────────────────────────────────────────────────────────────
5:18:50 PM: ​
5:18:50 PM: ❯ Version
5:18:50 PM: @netlify/build 28.1.4
5:18:50 PM: ​
5:18:50 PM: ❯ Flags
5:18:50 PM: baseRelDir: true
5:18:50 PM: buildId: 636065c6b0699400093ae519
5:18:50 PM: deployId: 636065c6b0699400093ae51b
5:18:50 PM: ​
5:18:50 PM: ❯ Current directory
5:18:50 PM: /opt/build/repo
5:18:50 PM: ​
5:18:50 PM: ❯ Config file
5:18:50 PM: /opt/build/repo/netlify.toml
5:18:50 PM: ​
5:18:50 PM: ❯ Context
5:18:50 PM: production
5:18:50 PM: ​
5:18:50 PM: ────────────────────────────────────────────────────────────────
5:18:50 PM: 1. build.command from netlify.toml
5:18:50 PM: ────────────────────────────────────────────────────────────────
5:18:50 PM: ​
5:18:50 PM: $ CI= npm run build
5:18:50 PM: > my-portfolio@0.1.0 build
5:18:50 PM: > craco build
5:18:52 PM: craco: *** Cannot find ESLint loader (eslint-loader). ***
5:18:52 PM: /opt/build/repo/node_modules/@craco/craco/lib/features/webpack/style/postcss.js:54
5:18:52 PM: craPlugins = match.loader.options.plugins();
5:18:52 PM: ^
5:18:52 PM: TypeError: match.loader.options.plugins is not a function
5:18:52 PM: at extendsPostcss (/opt/build/repo/node_modules/@craco/craco/lib/features/webpack/style/postcss.js:54:51)
5:18:52 PM: at overrideLoader (/opt/build/repo/node_modules/@craco/craco/lib/features/webpack/style/postcss.js:97:9)
5:18:52 PM: at /opt/build/repo/node_modules/@craco/craco/lib/features/webpack/style/postcss.js:118:13
5:18:52 PM: at Array.forEach ()
5:18:52 PM: at overridePostcss (/opt/build/repo/node_modules/@craco/craco/lib/features/webpack/style/postcss.js:117:17)
5:18:52 PM: at overrideStyle (/opt/build/repo/node_modules/@craco/craco/lib/features/webpack/style/style.js:9:25)
5:18:52 PM: at mergeWebpackConfig (/opt/build/repo/node_modules/@craco/craco/lib/features/webpack/merge-webpack-config.js:48:30)
5:18:52 PM: at overrideWebpackProd (/opt/build/repo/node_modules/@craco/craco/lib/features/webpack/override.js:18:36)
5:18:52 PM: at /opt/build/repo/node_modules/@craco/craco/scripts/build.js:23:5
5:18:52 PM: ​
5:18:52 PM: Creating deploy upload records
5:18:52 PM: ────────────────────────────────────────────────────────────────
5:18:52 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)
5:18:52 PM: “build.command” failed
5:18:52 PM: ────────────────────────────────────────────────────────────────
5:18:52 PM: ​
5:18:52 PM: Error message
5:18:52 PM: Command failed with exit code 1: CI= npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
5:18:52 PM: ​
5:18:52 PM: Error location
5:18:52 PM: In build.command from netlify.toml:
5:18:52 PM: CI= npm run build
5:18:52 PM: ​
5:18:52 PM: Resolved config
5:18:52 PM: build:
5:18:52 PM: command: CI= npm run build
5:18:52 PM: commandOrigin: config
5:18:52 PM: publish: /opt/build/repo/dist
5:18:52 PM: publishOrigin: ui
5:18:52 PM: redirects:
5:18:52 PM: - from: /* status: 200 to: /index.html redirectsOrigin: configCaching artifacts
5:18:52 PM: Started saving node modules
5:18:52 PM: Finished saving node modules
5:18:52 PM: Started saving build plugins
5:18:52 PM: Finished saving build plugins
5:18:52 PM: Started saving pip cache
5:18:52 PM: Finished saving pip cache
5:18:52 PM: Started saving emacs cask dependencies
5:18:52 PM: Finished saving emacs cask dependencies
5:18:52 PM: Started saving maven dependencies
5:18:52 PM: Finished saving maven dependencies
5:18:52 PM: Started saving boot dependencies
5:18:52 PM: Finished saving boot dependencies
5:18:52 PM: Started saving rust rustup cache
5:18:52 PM: Finished saving rust rustup cache
5:18:52 PM: Started saving go dependencies
5:18:52 PM: Finished saving go dependencies
5:18:52 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:18:52 PM: Failing build: Failed to build site
5:18:52 PM: Finished processing build request in 35.890854519s

Hey there,

Reading your deploy log, I am seeing:

5:18:52 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](https://ntl.fyi/exit-code-2))
5:18:52 PM: “build.command” failed
5:18:52 PM: ────────────────────────────────────────────────────────────────
5:18:52 PM: ​
5:18:52 PM: Error message
5:18:52 PM: Command failed with exit code 1: CI= npm run build ([Search results for '"non-zero exit code: 1"' - Netlify Support Forums](https://ntl.fyi/exit-code-1))
5:18:52 PM: ​
5:18:52 PM: Error location
5:18:52 PM: In build.command from netlify.toml:
5:18:52 PM: CI= npm run build

Can you try changing your build command? Here is a helpful thread where a fellow forums member shared their solution:

Thanks for your help Hilary!

I’ve tried the following build commands in my netlify.toml file:

  • npm install --force && npm run build
  • npm install --force && CI= npm run build
  • npm install && CI= npm run build
  • cd client && npm run build

None were successful. My site builds locally. I must be missing something here, thank you for the extra set of eyes on this. Any other ideas?

This might be useful:

Thanks for your help! I wasn’t able to get it to work after running npm update craco-less. I got the same error message you highlighted, again. I’ve retraced my steps and reverted back to an older, but working, version. I’ll try to add the logos another way.