Home
Support Forums

Issue deploying react app: Build script returned non-zero exit code: 2

Hi there,

I’m quite new in deploying a React Application.

I’m having the following error: Build script returned non-zero exit code: 2
Site name: happy-neumann-cc0b06.netlify.app

I would very much appreciate your help.

Here is the log:

2:32:21 PM: Build ready to start
2:32:23 PM: build-image version: 3bcb38c35508b42e9121d4badfe6d8c66fd7a3f0
2:32:23 PM: build-image tag: v4.3.2
2:32:23 PM: buildbot version: 04fb57a6b52e36fc0fd306c97e17aa22ebf93b50
2:32:23 PM: Fetching cached dependencies
2:32:23 PM: Failed to fetch cache, continuing with build
2:32:23 PM: Starting to prepare the repo for build
2:32:23 PM: No cached dependencies found. Cloning fresh repo
2:32:23 PM: git clone GitHub - AnouarLdn/react-guest-list
2:32:24 PM: Preparing Git Reference refs/heads/master
2:32:24 PM: Parsing package.json dependencies
2:32:25 PM: Starting build script
2:32:25 PM: Installing dependencies
2:32:25 PM: Python version set to 2.7
2:32:26 PM: Downloading and installing node v12.16.2…
2:32:26 PM: Downloading https://nodejs.org/dist/v12.16.2/node-v12.16.2-linux-x64.tar.xz
2:32:26 PM: Computing checksum with sha256sum
2:32:26 PM: Checksums matched!
2:32:28 PM: Now using node v12.16.2 (npm v6.14.4)
2:32:29 PM: Started restoring cached build plugins
2:32:29 PM: Finished restoring cached build plugins
2:32:29 PM: Attempting ruby version 2.7.2, read from environment
2:32:30 PM: Using ruby version 2.7.2
2:32:31 PM: Using PHP version 8.0
2:32:31 PM: Started restoring cached node modules
2:32:31 PM: Finished restoring cached node modules
2:32:31 PM: Installing NPM modules using NPM version 6.14.4
2:33:10 PM: > core-js@2.6.12 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
2:33:10 PM: > node -e “try{require(’./postinstall’)}catch(e){}”
2:33:10 PM: > core-js@3.16.4 postinstall /opt/build/repo/node_modules/core-js
2:33:10 PM: > node -e “try{require(’./postinstall’)}catch(e){}”
2:33:10 PM: > core-js-pure@3.16.4 postinstall /opt/build/repo/node_modules/core-js-pure
2:33:10 PM: > node -e “try{require(’./postinstall’)}catch(e){}”
2:33:10 PM: > ejs@2.7.4 postinstall /opt/build/repo/node_modules/ejs
2:33:10 PM: > node ./postinstall.js
2:33:13 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/webpack-dev-server/node_modules/fsevents):
2:33:13 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
2:33:13 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/watchpack-chokidar2/node_modules/fsevents):
2:33:13 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
2:33:13 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
2:33:13 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {“os”:“darwin”,“arch”:“any”} (current: {“os”:“linux”,“arch”:“x64”})
2:33:13 PM: added 1946 packages from 741 contributors and audited 1952 packages in 41.601s
2:33:15 PM: 148 packages are looking for funding
2:33:15 PM: run npm fund for details
2:33:15 PM: found 46 vulnerabilities (27 moderate, 18 high, 1 critical)
2:33:15 PM: run npm audit fix to fix them, or npm audit for details
2:33:15 PM: NPM modules installed
2:33:15 PM: Started restoring cached go cache
2:33:15 PM: Finished restoring cached go cache
2:33:15 PM: go version go1.16.5 linux/amd64
2:33:15 PM: go version go1.16.5 linux/amd64
2:33:15 PM: Installing missing commands
2:33:15 PM: Verify run directory
2:33:17 PM: ​
2:33:17 PM: ────────────────────────────────────────────────────────────────
2:33:17 PM: Netlify Build
2:33:17 PM: ────────────────────────────────────────────────────────────────
2:33:17 PM: ​
2:33:17 PM: ❯ Version
2:33:17 PM: @netlify/build 18.17.0
2:33:17 PM: ​
2:33:17 PM: ❯ Flags
2:33:17 PM: baseRelDir: true
2:33:17 PM: buildId: 61682355251a2f0007b1842a
2:33:17 PM: deployId: 61682355251a2f0007b1842c
2:33:17 PM: ​
2:33:17 PM: ❯ Current directory
2:33:17 PM: /opt/build/repo
2:33:17 PM: ​
2:33:17 PM: ❯ Config file
2:33:17 PM: /opt/build/repo/netlify.toml
2:33:17 PM: ​
2:33:17 PM: ❯ Context
2:33:17 PM: production
2:33:17 PM: ​
2:33:17 PM: ────────────────────────────────────────────────────────────────
2:33:17 PM: 1. Build command from Netlify app
2:33:17 PM: ────────────────────────────────────────────────────────────────
2:33:17 PM: ​
2:33:17 PM: $ npm run build
2:33:17 PM: > todolist-app@0.1.0 build /opt/build/repo
2:33:17 PM: > react-scripts build
2:33:19 PM: Creating an optimized production build…
2:33:29 PM:
2:33:29 PM: Treating warnings as errors because process.env.CI = true.
2:33:29 PM: Most CI servers set it automatically.
2:33:29 PM:
2:33:29 PM: Failed to compile.
2:33:29 PM:
2:33:29 PM: src/App.js
2:33:29 PM: Line 2:8: ‘stylesheet’ is defined but never used no-unused-vars
2:33:29 PM: npm ERR! code ELIFECYCLE
2:33:29 PM: npm ERR! errno 1
2:33:29 PM: npm ERR! todolist-app@0.1.0 build: react-scripts build
2:33:29 PM: npm ERR! Exit status 1
2:33:29 PM: npm ERR!
2:33:29 PM: npm ERR! Failed at the todolist-app@0.1.0 build script.
2:33:29 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2:33:29 PM: npm ERR! A complete log of this run can be found in:
2:33:29 PM: npm ERR! /opt/buildhome/.npm/_logs/2021-10-14T12_33_29_176Z-debug.log
2:33:29 PM: ​
2:33:29 PM: ────────────────────────────────────────────────────────────────
2:33:29 PM: “build.command” failed
2:33:29 PM: ────────────────────────────────────────────────────────────────
2:33:29 PM: ​
2:33:29 PM: Error message
2:33:29 PM: Command failed with exit code 1: npm run build
2:33:29 PM: ​
2:33:29 PM: Error location
2:33:29 PM: In Build command from Netlify app:
2:33:29 PM: npm run build
2:33:29 PM: ​
2:33:29 PM: Resolved config
2:33:29 PM: build:
2:33:29 PM: command: npm run build
2:33:29 PM: commandOrigin: ui
2:33:29 PM: environment:
2:33:29 PM: - NODE_VERSION
2:33:29 PM: publish: /opt/build/repo/build
2:33:29 PM: publishOrigin: ui
2:33:29 PM: Caching artifacts
2:33:29 PM: Started saving node modules
2:33:29 PM: Finished saving node modules
2:33:29 PM: Started saving build plugins
2:33:29 PM: Finished saving build plugins
2:33:29 PM: Started saving pip cache
2:33:29 PM: Finished saving pip cache
2:33:29 PM: Started saving emacs cask dependencies
2:33:29 PM: Finished saving emacs cask dependencies
2:33:29 PM: Started saving maven dependencies
2:33:29 PM: Finished saving maven dependencies
2:33:29 PM: Started saving boot dependencies
2:33:29 PM: Finished saving boot dependencies
2:33:29 PM: Started saving rust rustup cache
2:33:29 PM: Finished saving rust rustup cache
2:33:29 PM: Started saving go dependencies
2:33:29 PM: Finished saving go dependencies
2:33:32 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:33:32 PM: Creating deploy upload records
2:33:32 PM: Failing build: Failed to build site
2:33:32 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
2:33:32 PM: Finished processing build request in 1m9.755011998s

Many thanks!

Hi @AnouarSE15

There is a variable stylesheet that is defined but never used. This triggers a warning. As warnings are treated as errors (per the message above from the log) the build fails.

Remove the unused variable and the build should succeed (assuming no other errors.) Alternatively, change the build command and CI='' npm run build to ignore such warnings and build regardless.

2 Likes

Thanks very much Coelmay, it works. :+1: