Build error for my MERN frontend project

Hi I am trying to deploy my project from github but it is failing during the build.
Please find logs below

4:18:53 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)
4:18:33 PM: Netlify Build
4:18:33 PM: ────────────────────────────────────────────────────────────────
4:18:33 PM: ​
4:18:33 PM: ❯ Version
4:18:33 PM: @netlify/build 29.17.4
4:18:33 PM: ​
4:18:33 PM: ❯ Flags
4:18:33 PM: baseRelDir: true
4:18:33 PM: buildId: 64ce28e530bde62da6e9983c
4:18:33 PM: deployId: 64ce28e530bde62da6e9983e
4:18:33 PM: ​
4:18:33 PM: ❯ Current directory
4:18:33 PM: /opt/build/repo
4:18:33 PM: ​
4:18:33 PM: ❯ Config file
4:18:33 PM: No config file was defined: using default values.
4:18:33 PM: ​
4:18:33 PM: ❯ Context
4:18:33 PM: production
4:18:33 PM: ​
4:18:33 PM: Build command from Netlify app
4:18:33 PM: ────────────────────────────────────────────────────────────────
4:18:33 PM: ​
4:18:33 PM: $ npm run build
4:18:33 PM: > frontend@0.1.0 build
4:18:33 PM: > react-scripts build
4:18:34 PM: Creating an optimized production build…
4:18:51 PM:
4:18:51 PM: Treating warnings as errors because process.env.CI = true.
4:18:51 PM: Most CI servers set it automatically.
4:18:51 PM:
4:18:51 PM: Failed to compile.
4:18:51 PM:
4:18:51 PM: Warning
4:18:51 PM: (6:29521) autoprefixer: Replace color-adjust to print-color-adjust. The color-adjust shorthand is currently deprecated.
4:18:51 PM: [eslint]
4:18:51 PM: src/pages/admin/AdminUsersPage.js
4:18:51 PM: Line 3:10: ‘Link’ is defined but never used no-unused-vars
4:18:51 PM: ​
4:18:51 PM: build.command failed
4:18:51 PM: ────────────────────────────────────────────────────────────────
4:18:51 PM: ​
4:18:51 PM: Error message
4:18:51 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
4:18:51 PM: ​
4:18:51 PM: Error location
4:18:51 PM: In Build command from Netlify app:
4:18:51 PM: npm run build
4:18:51 PM: ​
4:18:51 PM: Resolved config
4:18:51 PM: build:
4:18:51 PM: command: npm run build
4:18:51 PM: commandOrigin: ui
4:18:51 PM: publish: /opt/build/repo/build
4:18:51 PM: publishOrigin: ui
4:18:53 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:18:53 PM: Failing build: Failed to build site
4:18:53 PM: Finished processing build request in 46.52s

My Git hub repo

As it says CI is set to true by default and treats warnings as errors, and errors cause your build to fail.

If you don’t want to fix the warnings, or to have it fail on warnings, then you want to set CI to false.

An easy way to do so is to change your build command to CI= npm run build

1 Like

Thanks, Nathanmartin. It worked.