Exit code 1 and exit code 2 errors for React Project

Hi everyone, I keep on getting these two errors and even asked chat gpt for help but no luck. I have tried re-deploying my app by clearing cache as well. I am really stumped and have no idea what it wrong. Everything works perfectly on localhost. Any help is greatly appreciated.

2:07:59 PM: build-image version: 91488c6c0412f5c1c00fb34eff5c1fc41a32bce9 (focal)
2:07:59 PM: buildbot version: 91488c6c0412f5c1c00fb34eff5c1fc41a32bce9
2:07:59 PM: Fetching cached dependencies
2:07:59 PM: Failed to fetch cache, continuing with build
2:07:59 PM: Starting to prepare the repo for build
2:07:59 PM: No cached dependencies found. Cloning fresh repo
2:07:59 PM: git clone --filter=blob:none https://github.com/Paulette-Zaldivar-Flores/EZ-Cocktails
2:07:59 PM: Preparing Git Reference refs/heads/main
2:08:00 PM: Parsing package.json dependencies
2:08:02 PM: Starting to install dependencies
2:08:02 PM: Python version set to 3.8
2:08:02 PM: Attempting Ruby version 2.7.2, read from environment
2:08:02 PM: Using Ruby version 2.7.2
2:08:03 PM: Started restoring cached go cache
2:08:03 PM: Finished restoring cached go cache
2:08:03 PM: Installing Go version 1.19.5 (requested 1.19.5)
2:08:09 PM: go version go1.19.5 linux/amd64
2:08:09 PM: Using PHP version 8.0
2:08:10 PM: v16.20.0 is already installed.
2:08:10 PM: Now using node v16.20.0 (npm v8.19.4)
2:08:10 PM: Enabling Node.js Corepack
2:08:10 PM: Started restoring cached build plugins
2:08:10 PM: Finished restoring cached build plugins
2:08:10 PM: Started restoring cached corepack dependencies
2:08:10 PM: Finished restoring cached corepack dependencies
2:08:10 PM: Started restoring cached yarn cache
2:08:10 PM: Finished restoring cached yarn cache
2:08:11 PM: No yarn workspaces detected
2:08:11 PM: Started restoring cached node modules
2:08:11 PM: Finished restoring cached node modules
2:08:11 PM: Installing npm packages using Yarn version 1.22.19
2:08:11 PM: yarn install v1.22.19
2:08:11 PM: warning package.json: No license field
2:08:11 PM: warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
2:08:11 PM: warning v40-geckos-team-20@0.1.0: No license field
2:08:11 PM: [1/4] Resolving packages...
2:08:12 PM: [2/4] Fetching packages...
2:08:23 PM: [3/4] Linking dependencies...
2:08:23 PM: warning " > @testing-library/user-event@13.5.0" has unmet peer dependency "@testing-library/dom@>=7.21.4".
2:08:23 PM: warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-syntax-flow@^7.14.5".
2:08:23 PM: warning "react-scripts > eslint-config-react-app > eslint-plugin-flowtype@8.0.3" has unmet peer dependency "@babel/plugin-transform-react-jsx@^7.14.9".
2:08:23 PM: warning "react-scripts > react-dev-utils > fork-ts-checker-webpack-plugin@6.5.3" has unmet peer dependency "typescript@>= 2.7".
2:08:23 PM: warning "react-scripts > eslint-config-react-app > @typescript-eslint/eslint-plugin > tsutils@3.21.0" has unmet peer dependency "typescript@>=2.8.0 || >= 3.2.0-dev || >= 3.3.0-dev || >= 3.4.0-dev || >= 3.5.0-dev || >= 3.6.0-dev || >= 3.6.0-beta || >= 3.7.0-dev || >= 3.7.0-beta".
2:08:23 PM: warning " > styled-components@5.3.9" has unmet peer dependency "react-is@>= 16.8.0".
2:08:28 PM: [4/4] Building fresh packages...
2:08:29 PM: Done in 17.61s.
2:08:29 PM: npm packages installed using Yarn
2:08:29 PM: Install dependencies script success
2:08:29 PM: Starting build script
2:08:30 PM: Detected 1 framework(s)
2:08:30 PM: "create-react-app" at version "5.0.1"
2:08:30 PM: Section completed: initializing
2:08:31 PM: ​
2:08:31 PM:   Netlify Build                                                 
2:08:31 PM: ────────────────────────────────────────────────────────────────
2:08:31 PM: ​
2:08:31 PM: ❯ Version
2:08:31 PM:   @netlify/build 29.9.2
2:08:31 PM: ​
2:08:31 PM: ❯ Flags
2:08:31 PM:   baseRelDir: true
2:08:31 PM:   buildId: 643a3129d2febc00089a6a97
2:08:31 PM:   deployId: 643a3129d2febc00089a6a99
2:08:31 PM: ​
2:08:31 PM: ❯ Current directory
2:08:31 PM:   /opt/build/repo
2:08:31 PM: ​
2:08:31 PM: ❯ Config file
2:08:31 PM:   No config file was defined: using default values.
2:08:31 PM: ​
2:08:31 PM: ❯ Context
2:08:31 PM:   production
2:08:31 PM: ​
2:08:31 PM:   1. Build command from Netlify app                             
2:08:31 PM: ────────────────────────────────────────────────────────────────
2:08:31 PM: ​
2:08:31 PM: $ npm run build
2:08:31 PM: > v40-geckos-team-20@0.1.0 build
2:08:31 PM: > react-scripts build
2:08:33 PM: Creating an optimized production build...
2:08:41 PM: 
2:08:41 PM: Treating warnings as errors because process.env.CI = true.
2:08:41 PM: Most CI servers set it automatically.
2:08:41 PM: 
2:08:41 PM: Failed to compile.
2:08:41 PM: 
2:08:41 PM: [eslint]
2:08:41 PM: src/components/CocktailDetails/CocktailDetails.js
2:08:41 PM:   Line 2:21:   'Link' is defined but never used           no-unused-vars
2:08:41 PM:   Line 28:11:  'IDLE' is assigned a value but never used  no-unused-vars
2:08:41 PM: ​
2:08:41 PM:   "build.command" failed                                        
2:08:41 PM: ────────────────────────────────────────────────────────────────
2:08:41 PM: ​
2:08:41 PM:   Error message
2:08:41 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
2:08:41 PM: ​
2:08:41 PM:   Error location
2:08:41 PM:   In Build command from Netlify app:
2:08:41 PM:   npm run build
2:08:41 PM: ​
2:08:41 PM:   Resolved config
2:08:41 PM:   build:
2:08:41 PM:     command: npm run build
2:08:41 PM:     commandOrigin: ui
2:08:41 PM:     publish: /opt/build/repo/build
2:08:41 PM:     publishOrigin: ui
2:08:41 PM: Caching artifacts
2:08:41 PM: Started saving node modules
2:08:41 PM: Finished saving node modules
2:08:41 PM: Started saving build plugins
2:08:41 PM: Finished saving build plugins
2:08:41 PM: Started saving corepack cache
2:08:41 PM: Finished saving corepack cache
2:08:41 PM: Started saving yarn cache
2:08:43 PM: Finished saving yarn cache
2:08:43 PM: Started saving pip cache
2:08:43 PM: Finished saving pip cache
2:08:43 PM: Started saving emacs cask dependencies
2:08:43 PM: Finished saving emacs cask dependencies
2:08:43 PM: Started saving maven dependencies
2:08:43 PM: Finished saving maven dependencies
2:08:43 PM: Started saving boot dependencies
2:08:43 PM: Finished saving boot dependencies
2:08:43 PM: Started saving rust rustup cache
2:08:43 PM: Finished saving rust rustup cache
2:08:43 PM: Started saving go dependencies
2:08:43 PM: Finished saving go dependencies
2:08:43 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:08:43 PM: Failing build: Failed to build site
2:08:43 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
2:08:44 PM: Finished processing build request in 44.728s

ChatGPT couldn’t figure this out!? Curious.

The lines above is telling you that a warning in the code is treated as an error during build.

Below is the warning from the build log.

You have a couple of options to remedy this:

  1. Remove the Link and IDLE variables that are not used. This has the added benefit of cleaning up the codef.
  2. Change the build command to CI= npm run build which sets CI to false meaning only errors are treated as errors.