Failing to compile with exit code 1 & 2

PLEASE help us help you by writing a good post!

  • Netlify site name: creative-syrniki-5cc8b5
    Hi, so I set up a deploy directly from my GitHub and on my first build it has failed to compile. It has said in the log that the “build.command” failed I have doubled check and I thought this meant the command that is used to build the site, I have it set to ‘npm run build’. I am using create-react-app as an fyi.

Here is the log:

3:50:08 PM: build-image version: d55944c047ef0aee2ac01971edde72cb2a50acfe (focal)
3:50:08 PM: build-image tag: v4.16.1
3:50:08 PM: buildbot version: 0be68edd034c744ad79b207db44f42646b4e8ecb
3:50:08 PM: Fetching cached dependencies
3:50:08 PM: Failed to fetch cache, continuing with build
3:50:08 PM: Starting to prepare the repo for build
3:50:08 PM: No cached dependencies found. Cloning fresh repo
3:50:08 PM: git clone --filter=blob:none https://github.com/JackTubby/react-weather-app
3:50:09 PM: Preparing Git Reference refs/heads/main
3:50:09 PM: Parsing package.json dependencies
3:50:10 PM: Starting build script
3:50:10 PM: Installing dependencies
3:50:10 PM: Python version set to 2.7
3:50:11 PM: v16.19.0 is already installed.
3:50:11 PM: Now using node v16.19.0 (npm v8.19.3)
3:50:11 PM: Enabling node corepack
3:50:11 PM: Started restoring cached build plugins
3:50:11 PM: Finished restoring cached build plugins
3:50:11 PM: Attempting ruby version 2.7.2, read from environment
3:50:12 PM: Using ruby version 2.7.2
3:50:12 PM: Using PHP version 8.0
3:50:12 PM: No npm workspaces detected
3:50:12 PM: Started restoring cached node modules
3:50:12 PM: Finished restoring cached node modules
3:50:12 PM: Installing NPM modules using NPM version 8.19.3
3:50:13 PM: npm WARN old lockfile
3:50:13 PM: npm WARN old lockfile The package-lock.json file was created with an old version of npm,
3:50:13 PM: npm WARN old lockfile so supplemental metadata must be fetched from the registry.
3:50:13 PM: npm WARN old lockfile
3:50:13 PM: npm WARN old lockfile This is a one-time fix-up, please be patient...
3:50:13 PM: npm WARN old lockfile
3:50:21 PM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
3:50:21 PM: npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
3:50:21 PM: npm WARN deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
3:50:23 PM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
3:50:27 PM: added 1464 packages, and audited 1465 packages in 15s
3:50:27 PM: 224 packages are looking for funding
3:50:27 PM:   run `npm fund` for details
3:50:27 PM: 7 high severity vulnerabilities
3:50:27 PM: To address issues that do not require attention, run:
3:50:27 PM:   npm audit fix
3:50:27 PM: To address all issues (including breaking changes), run:
3:50:27 PM:   npm audit fix --force
3:50:27 PM: Run `npm audit` for details.
3:50:27 PM: NPM modules installed
3:50:27 PM: Creating package sha
3:50:28 PM: Started restoring cached go cache
3:50:28 PM: Finished restoring cached go cache
3:50:29 PM: go version go1.19.4 linux/amd64
3:50:29 PM: Detected 1 framework(s)
3:50:29 PM: "create-react-app" at version "5.0.1"
3:50:29 PM: Installing missing commands
3:50:29 PM: Verify run directory
3:50:29 PM: Section completed: initializing
3:50:30 PM: ​
3:50:30 PM:   Netlify Build                                                 
3:50:30 PM: ────────────────────────────────────────────────────────────────
3:50:30 PM: ​
3:50:30 PM: ❯ Version
3:50:30 PM:   @netlify/build 29.2.1
3:50:30 PM: ​
3:50:30 PM: ❯ Flags
3:50:30 PM:   baseRelDir: true
3:50:30 PM:   buildId: 63ac65ae3c8e6c004e943e34
3:50:30 PM:   deployId: 63ac65ae3c8e6c004e943e36
3:50:30 PM: ​
3:50:30 PM: ❯ Current directory
3:50:30 PM:   /opt/build/repo
3:50:30 PM: ​
3:50:30 PM: ❯ Config file
3:50:30 PM:   No config file was defined: using default values.
3:50:30 PM: ​
3:50:30 PM: ❯ Context
3:50:30 PM:   production
3:50:30 PM: ​
3:50:30 PM:   1. Build command from Netlify app                             
3:50:30 PM: ────────────────────────────────────────────────────────────────
3:50:30 PM: ​
3:50:30 PM: $ npm run build
3:50:30 PM: > react-weather-app@0.1.0 build
3:50:30 PM: > react-scripts build
3:50:31 PM: Creating an optimized production build...
3:50:40 PM: 
3:50:40 PM: Treating warnings as errors because process.env.CI = true.
3:50:40 PM: Most CI servers set it automatically.
3:50:40 PM: 
3:50:40 PM: Failed to compile.
3:50:40 PM: 
3:50:40 PM: [eslint]
3:50:40 PM: src/scenes/current-weather/CurrentWeather.jsx
3:50:40 PM:   Line 12:5:  'clouds' is assigned a value but never used  no-unused-vars
3:50:40 PM: src/scenes/forcast/Forcast.jsx
3:50:40 PM:   Line 27:18:  Expected '===' and instead saw '=='  eqeqeq
3:50:40 PM:   Line 49:18:  Expected '===' and instead saw '=='  eqeqeq
3:50:40 PM:   Line 66:23:  Expected '===' and instead saw '=='  eqeqeq
3:50:40 PM:   Line 69:24:  Expected '===' and instead saw '=='  eqeqeq
3:50:40 PM: src/scenes/forcast/five-day-forcast/FiveDay.jsx
3:50:40 PM:   Line 1:17:  'useState' is defined but never used  no-unused-vars
3:50:40 PM: src/scenes/forcast/weather-block/WeatherBlock.jsx
3:50:40 PM:   Line 11:31:  Expected '===' and instead saw '=='                                                                                                                                                                                                                                                                           eqeqeq
3:50:40 PM:   Line 14:29:  Expected '===' and instead saw '=='                                                                                                                                                                                                                                                                           eqeqeq
3:50:40 PM:   Line 17:34:  Expected '===' and instead saw '=='                                                                                                                                                                                                                                                                           eqeqeq
3:50:40 PM:   Line 20:34:  Expected '===' and instead saw '=='                                                                                                                                                                                                                                                                           eqeqeq
3:50:40 PM:   Line 27:10:  React Hook useEffect has missing dependencies: 'checkIfDateOrTime', 'props.d_or_t', and 'props.identifier'. Either include them or remove the dependency array. You can also do a functional update 'setCheckIfDateOrTime(c => ...)' if you only need 'checkIfDateOrTime' in the 'setCheckIfDateOrTime' call  react-hooks/exhaustive-deps
3:50:40 PM: ​
3:50:40 PM:   "build.command" failed                                        
3:50:40 PM: ────────────────────────────────────────────────────────────────
3:50:40 PM: ​
3:50:40 PM:   Error message
3:50:40 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
3:50:40 PM: ​
3:50:40 PM:   Error location
3:50:40 PM:   In Build command from Netlify app:
3:50:42 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
3:50:40 PM:   npm run build
3:50:40 PM: ​
3:50:40 PM:   Resolved config
3:50:40 PM:   build:
3:50:40 PM:     command: npm run build
3:50:40 PM:     commandOrigin: ui
3:50:40 PM:     publish: /opt/build/repo/build
3:50:40 PM:     publishOrigin: ui
3:50:41 PM: Caching artifacts
3:50:41 PM: Started saving node modules
3:50:41 PM: Finished saving node modules
3:50:41 PM: Started saving build plugins
3:50:41 PM: Finished saving build plugins
3:50:41 PM: Started saving pip cache
3:50:41 PM: Finished saving pip cache
3:50:41 PM: Started saving emacs cask dependencies
3:50:41 PM: Finished saving emacs cask dependencies
3:50:41 PM: Started saving maven dependencies
3:50:41 PM: Finished saving maven dependencies
3:50:41 PM: Started saving boot dependencies
3:50:41 PM: Finished saving boot dependencies
3:50:41 PM: Started saving rust rustup cache
3:50:41 PM: Finished saving rust rustup cache
3:50:41 PM: Started saving go dependencies
3:50:41 PM: Finished saving go dependencies
3:50:41 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:50:41 PM: Failing build: Failed to build site
3:50:42 PM: Finished processing build request in 33.87172945s

Hi @mxhaib :wave:t6: , welcome to the forums! :netliconfetti: Can you try the following please only AFTER you got it working locally first?

  • check the version of node and npm installed on your computer
  • set the environment variables in netlify: NODE_VERSION with value of the version installed on your computer. Do the same with NPM_VERSION

If that doesn’t help please give this support guide a read.