Build was terminated: Build script returned non-zero exit code: 1 - Gatsby version 5 - RESOLVED

I recently created a new branch which involved updating my outdated packages (mostly updating Gatsby to version 5).

However, it doesn’t seem to build in Netlify. It builds locally just fine, but fails in netlify.

Here’s the output from Netlify:

9:35:04 PM: build-image version: 4c0c1cadee6a31c9bb8d824514030009c4c05c6a (focal)
9:35:04 PM: build-image tag: v4.15.0
9:35:04 PM: buildbot version: 9ef4dba9386902658d5cc7ad8ca0406443896076
9:35:04 PM: Building without cache
9:35:04 PM: Starting to prepare the repo for build
9:35:04 PM: No cached dependencies found. Cloning fresh repo
9:35:04 PM: git clone https://github.com/JB-26/website-portfolio
9:35:05 PM: Preparing Git Reference pull/34/head
9:35:05 PM: Parsing package.json dependencies
9:35:06 PM: Section completed: initializing
9:35:07 PM: Starting build script
9:35:07 PM: Installing dependencies
9:35:07 PM: Python version set to 2.7
9:35:07 PM: Attempting node version 'v19.2.0' from .nvmrc
9:35:07 PM: Downloading and installing node v19.2.0...
9:35:07 PM: Downloading https://nodejs.org/dist/v19.2.0/node-v19.2.0-linux-x64.tar.xz...
9:35:07 PM: Computing checksum with sha256sum
9:35:08 PM: Checksums matched!
9:35:10 PM: Now using node v19.2.0 (npm v8.19.3)
9:35:10 PM: Enabling node corepack
9:35:10 PM: Started restoring cached build plugins
9:35:10 PM: Finished restoring cached build plugins
9:35:10 PM: Attempting ruby version 2.7.2, read from environment
9:35:10 PM: Using ruby version 2.7.2
9:35:11 PM: Using PHP version 8.0
9:35:11 PM: No npm workspaces detected
9:35:11 PM: Started restoring cached node modules
9:35:11 PM: Finished restoring cached node modules
9:35:11 PM: Installing NPM modules using NPM version 8.19.3
9:35:12 PM: npm ERR! code ERESOLVE
9:35:12 PM: npm ERR! ERESOLVE could not resolve
9:35:12 PM: npm ERR!
9:35:12 PM: npm ERR! While resolving: @reach/router@1.3.4
9:35:12 PM: Creating deploy upload records
9:35:12 PM: npm ERR! Found: react@18.2.0
9:35:12 PM: npm ERR! node_modules/react
9:35:12 PM: npm ERR!   react@"^18.2.0" from the root project
9:35:12 PM: npm ERR!   peer react@">=16.3" from @fortawesome/react-fontawesome@0.2.0
9:35:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1 (https://ntl.fyi/exit-code-1)
9:35:12 PM: npm ERR!   node_modules/@fortawesome/react-fontawesome
9:35:12 PM: npm ERR!     @fortawesome/react-fontawesome@"^0.2.0" from the root project
9:35:12 PM: npm ERR!   10 more (@gatsbyjs/reach-router, gatsby, gatsby-link, ...)
9:35:12 PM: npm ERR!
9:35:12 PM: npm ERR! Could not resolve dependency:
9:35:12 PM: npm ERR! peer react@"15.x || 16.x || 16.4.0-alpha.0911da3" from @reach/router@1.3.4
9:35:12 PM: npm ERR! node_modules/@reach/router
9:35:12 PM: npm ERR!   @reach/router@"^1.3.4" from the root project
9:35:12 PM: npm ERR!
9:35:12 PM: npm ERR! Conflicting peer dependency: react@16.14.0
9:35:12 PM: npm ERR! node_modules/react
9:35:12 PM: npm ERR!   peer react@"15.x || 16.x || 16.4.0-alpha.0911da3" from @reach/router@1.3.4
9:35:12 PM: npm ERR!   node_modules/@reach/router
9:35:12 PM: npm ERR!     @reach/router@"^1.3.4" from the root project
9:35:12 PM: npm ERR!
9:35:12 PM: npm ERR! Fix the upstream dependency conflict, or retry
9:35:12 PM: npm ERR! this command with --force, or --legacy-peer-deps
9:35:12 PM: npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
9:35:12 PM: npm ERR!
9:35:12 PM: npm ERR! See /opt/buildhome/.npm/eresolve-report.txt for a full report.
9:35:12 PM: npm ERR! A complete log of this run can be found in:
9:35:12 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-12-04T21_35_11_652Z-debug-0.log
9:35:12 PM: Error during NPM install
9:35:12 PM: Build was terminated: Build script returned non-zero exit code: 1
9:35:13 PM: Failing build: Failed to build site
9:35:13 PM: Finished processing build request in 9.021496245s

What could resolve this issue?

Just wanted to share that I resolved this issue by adding an environment variable to the site!

The variable was; NPM_FLAGS
Value; --legacy-peer-deps

Hopefully this helps anyone if they come across the same issue

Hi @JB-26! :wave:t6: Thanks for letting us know you were able to resolve your issue by adding an environment variable. :netliconfetti: This is super insightful and will certainly help our other users. We really appreciate the feedback. Happy building! :smiling_face_with_three_hearts: