Netlify: Build script returned non-zero exit code: 2

Viewed 299

I'm having an issue with deploying my create-react-app on netlify. When I try to run deploy, I get the error:

Build script returned non-zero exit code: 2

I have looked up other similar posts and saw that I should be using CI = npm run build and that I should set the environmental key to "CI" and value to "false". I have done both those things and then run the "clear cache and deploy" command and still get the error. When I run npm run build on my terminal it builds locally, so I know that works.

Not sure what I am doing wrong, but I would like for my app to be able to deploy automatically after I push to Github.

Here is my build log:

3:44:11 PM: Build ready to start
3:44:13 PM: build-image version: 3bcb38c35508b42e9121d4badfe6d8c66fd7a3f0
3:44:13 PM: build-image tag: v4.3.2
3:44:13 PM: buildbot version: fb5a2fdb274e5c7188f78d9274a70038778222d4
3:44:13 PM: Building without cache
3:44:13 PM: Starting to prepare the repo for build
3:44:13 PM: No cached dependencies found. Cloning fresh repo
3:44:13 PM: git clone https://github.com/vbrambila2/1RM
3:44:14 PM: Preparing Git Reference refs/heads/master
3:44:15 PM: Parsing package.json dependencies
3:44:15 PM: Starting build script
3:44:15 PM: Installing dependencies
3:44:15 PM: Python version set to 2.7
3:44:16 PM: Downloading and installing node v16.13.0...
3:44:16 PM: Downloading https://nodejs.org/dist/v16.13.0/node-v16.13.0-linux-x64.tar.xz...
3:44:17 PM: Computing checksum with sha256sum
3:44:17 PM: Checksums matched!
3:44:20 PM: Now using node v16.13.0 (npm v8.1.0)
3:44:20 PM: Started restoring cached build plugins
3:44:20 PM: Finished restoring cached build plugins
3:44:20 PM: Attempting ruby version 2.7.2, read from environment
3:44:22 PM: Using ruby version 2.7.2
3:44:22 PM: Using PHP version 8.0
3:44:22 PM: Started restoring cached node modules
3:44:22 PM: Finished restoring cached node modules
3:44:22 PM: Installing NPM modules using NPM version 8.1.0
3:44:39 PM: npm WARN deprecated flatten@1.0.3: flatten is deprecated in favor of utility frameworks such as lodash.
3:44:39 PM: npm WARN deprecated urix@0.1.0: Please see https://github.com/lydell/urix#deprecated
3:44:39 PM: npm WARN deprecated resolve-url@0.2.1: https://github.com/lydell/resolve-url#deprecated
3:44:40 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
3:44:40 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
3:44:43 PM: npm WARN deprecated querystring@0.2.1: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
3:44:44 PM: npm WARN deprecated sane@4.1.0: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
3:44:45 PM: npm WARN deprecated rollup-plugin-babel@4.4.0: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-babel.
3:44:51 PM: npm WARN deprecated babel-eslint@10.1.0: babel-eslint is now @babel/eslint-parser. This package will no longer receive updates.
3:44:53 PM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
3:44:53 PM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
3:44:53 PM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
3:44:55 PM: npm WARN deprecated querystring@0.2.0: The querystring API is considered Legacy. new code should use the URLSearchParams API instead.
3:44:55 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
3:44:56 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
3:44:56 PM: npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
3:44:58 PM: npm WARN deprecated @hapi/joi@15.1.1: Switch to 'npm install joi'
3:45:05 PM: npm WARN deprecated core-js@2.6.12: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
3:45:10 PM: added 2155 packages, and audited 2156 packages in 48s
3:45:10 PM: 161 packages are looking for funding
3:45:10 PM:   run `npm fund` for details
3:45:11 PM: 62 vulnerabilities (18 moderate, 42 high, 2 critical)
3:45:11 PM: To address issues that do not require attention, run:
3:45:11 PM:   npm audit fix
3:45:11 PM: To address all issues (including breaking changes), run:
3:45:11 PM:   npm audit fix --force
3:45:11 PM: Run `npm audit` for details.
3:45:11 PM: NPM modules installed
3:45:11 PM: Started restoring cached go cache
3:45:11 PM: Finished restoring cached go cache
3:45:11 PM: go version go1.16.5 linux/amd64
3:45:11 PM: go version go1.16.5 linux/amd64
3:45:11 PM: Installing missing commands
3:45:11 PM: Verify run directory
3:45:12 PM: ​
3:45:12 PM: ────────────────────────────────────────────────────────────────
3:45:12 PM:   Netlify Build                                                 
3:45:12 PM: ────────────────────────────────────────────────────────────────
3:45:12 PM: ​
3:45:12 PM: ❯ Version
3:45:12 PM:   @netlify/build 18.19.2
3:45:12 PM: ​
3:45:12 PM: ❯ Flags
3:45:12 PM:   baseRelDir: true
3:45:12 PM:   buildId: 617b27bbdd641c2e8a8ee159
3:45:12 PM:   deployId: 617b27bbdd641c2e8a8ee15b
3:45:12 PM: ​
3:45:12 PM: ❯ Current directory
3:45:12 PM:   /opt/build/repo
3:45:12 PM: ​
3:45:12 PM: ❯ Config file
3:45:12 PM:   No config file was defined: using default values.
3:45:12 PM: ​
3:45:12 PM: ❯ Context
3:45:12 PM:   production
3:45:13 PM: ​
3:45:13 PM: ────────────────────────────────────────────────────────────────
3:45:13 PM:   1. Build command from Netlify app                             
3:45:13 PM: ────────────────────────────────────────────────────────────────
3:45:13 PM: ​
3:45:13 PM: $ CI= npm run build
3:45:13 PM: > 1repmax@0.1.0 build
3:45:13 PM: > react-scripts build
3:45:15 PM: Creating an optimized production build...
3:45:20 PM: Failed to compile.
3:45:20 PM: 
3:45:20 PM: ./src/containers/AddPage.js
3:45:20 PM: Cannot find module: '@material-ui/icons/Add'. Make sure this package is installed.
3:45:20 PM: You can install this package by running: npm install @material-ui/icons/Add.
3:45:20 PM: ​
3:45:20 PM: ────────────────────────────────────────────────────────────────
3:45:20 PM:   "build.command" failed                                        
3:45:20 PM: ────────────────────────────────────────────────────────────────
3:45:20 PM: ​
3:45:20 PM:   Error message
3:45:20 PM:   Command failed with exit code 1: CI= npm run build
3:45:20 PM: ​
3:45:20 PM:   Error location
3:45:20 PM:   In Build command from Netlify app:
3:45:20 PM:   CI= npm run build
3:45:20 PM: ​
3:45:20 PM:   Resolved config
3:45:20 PM:   build:
3:45:20 PM:     command: CI= npm run build
3:45:20 PM:     commandOrigin: ui
3:45:20 PM:     environment:
3:45:20 PM:       - CI
3:45:20 PM:     publish: /opt/build/repo/build
3:45:20 PM:     publishOrigin: ui
3:45:20 PM: Caching artifacts
3:45:20 PM: Started saving node modules
3:45:20 PM: Finished saving node modules
3:45:20 PM: Started saving build plugins
3:45:20 PM: Finished saving build plugins
3:45:20 PM: Started saving pip cache
3:45:20 PM: Finished saving pip cache
3:45:20 PM: Started saving emacs cask dependencies
3:45:20 PM: Finished saving emacs cask dependencies
3:45:20 PM: Started saving maven dependencies
3:45:20 PM: Finished saving maven dependencies
3:45:20 PM: Started saving boot dependencies
3:45:20 PM: Finished saving boot dependencies
3:45:20 PM: Started saving rust rustup cache
3:45:20 PM: Finished saving rust rustup cache
3:45:20 PM: Started saving go dependencies
3:45:20 PM: Finished saving go dependencies
3:45:23 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:45:23 PM: Creating deploy upload records
3:45:23 PM: Failing build: Failed to build site
3:45:23 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:45:23 PM: Finished processing build request in 1m10.196368118s

0 Answers
Related