Getting Build error when deploying a react app

Hello.

When running the build command (npm run build) locally on my machine it works fine. However when trying to deploy it here in netlify I get an error. Here is my log.

Any help would be greatly appreciated:

app url: https://devcaco.netlify.app/

11:13:41 AM: build-image version: 68a2c262fa3c95a08a1716b8dde8fba0e332ec73 (focal)
11:13:41 AM: buildbot version: b549e06c0b968ceb54ca53dc179c6fe57df02730
11:13:41 AM: Building without cache
11:13:41 AM: Starting to prepare the repo for build
11:13:42 AM: No cached dependencies found. Cloning fresh repo
11:13:42 AM: git clone --filter=blob:none https://github.com/devcaco/finca_puricaure
11:13:42 AM: Preparing Git Reference refs/heads/main
11:13:42 AM: Parsing package.json dependencies
11:13:43 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'client/build' versus 'build' in the Netlify UI
11:13:44 AM: Starting to install dependencies
11:13:44 AM: Python version set to 3.8
11:13:44 AM: Attempting Ruby version 2.7.2, read from environment
11:13:44 AM: Using Ruby version 2.7.2
11:13:45 AM: Started restoring cached go cache
11:13:45 AM: Finished restoring cached go cache
11:13:45 AM: Installing Go version 1.19.5 (requested 1.19.5)
11:13:49 AM: go version go1.19.5 linux/amd64
11:13:50 AM: Using PHP version 8.0
11:13:51 AM: v16.20.0 is already installed.
11:13:51 AM: Now using node v16.20.0 (npm v8.19.4)
11:13:51 AM: Enabling Node.js Corepack
11:13:51 AM: Started restoring cached build plugins
11:13:51 AM: Finished restoring cached build plugins
11:13:51 AM: Started restoring cached corepack dependencies
11:13:51 AM: Finished restoring cached corepack dependencies
11:13:51 AM: No npm workspaces detected
11:13:51 AM: Started restoring cached node modules
11:13:51 AM: Finished restoring cached node modules
11:13:51 AM: Installing npm packages using npm version 8.19.4
11:14:18 AM: npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
11:14:18 AM: npm WARN deprecated rollup-plugin-terser@7.0.2: This package has been deprecated and is no longer maintained. Please use @rollup/plugin-terser
11:14:19 AM: 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
11:14:24 AM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
11:14:28 AM: added 1489 packages, and audited 1490 packages in 37s
11:14:28 AM: 236 packages are looking for funding
11:14:28 AM:   run `npm fund` for details
11:14:28 AM: 18 vulnerabilities (14 moderate, 4 high)
11:14:28 AM: To address issues that do not require attention, run:
11:14:28 AM:   npm audit fix
11:14:28 AM: To address all issues (including breaking changes), run:
11:14:28 AM:   npm audit fix --force
11:14:28 AM: Run `npm audit` for details.
11:14:28 AM: npm packages installed
11:14:28 AM: Install dependencies script success
11:14:28 AM: Starting build script
11:14:29 AM: Detected 1 framework(s)
11:14:29 AM: "create-react-app" at version "5.0.1"
11:14:29 AM: Section completed: initializing
11:14:31 AM: ​
11:14:31 AM:   Netlify Build                                                 
11:14:31 AM: ────────────────────────────────────────────────────────────────
11:14:31 AM: ​
11:14:31 AM: ❯ Version
11:14:31 AM:   @netlify/build 29.10.0
11:14:31 AM: ​
11:14:31 AM: ❯ Flags
11:14:31 AM:   baseRelDir: true
11:14:31 AM:   buildId: 6447ee2205590614f2a90449
11:14:31 AM:   deployId: 6447ee2205590614f2a9044b
11:14:31 AM: ​
11:14:31 AM: ❯ Current directory
11:14:31 AM:   /opt/build/repo/client
11:14:31 AM: ​
11:14:31 AM: ❯ Config file
11:14:31 AM:   No config file was defined: using default values.
11:14:31 AM: ​
11:14:31 AM: ❯ Context
11:14:31 AM:   production
11:14:31 AM: ​
11:14:31 AM:   1. Build command from Netlify app                             
11:14:31 AM: ────────────────────────────────────────────────────────────────
11:14:31 AM: ​
11:14:31 AM: $ npm run build
11:14:31 AM: > client@0.1.0 build
11:14:31 AM: > react-scripts build
11:14:32 AM: Creating an optimized production build...
11:15:10 AM: 
11:15:10 AM: Treating warnings as errors because process.env.CI = true.
11:15:10 AM: Most CI servers set it automatically.
11:15:10 AM: 
11:15:10 AM: Failed to compile.
11:15:10 AM: 
11:15:10 AM: [eslint]
11:15:10 AM: src/App.js
11:15:10 AM:   Line 14:9:  'navigate' is assigned a value but never used  no-unused-vars
11:15:10 AM: src/components/StockDetails.js
11:15:10 AM:   Line 17:27:  'setStockReposicion' is assigned a value but never used  no-unused-vars
11:15:10 AM: src/components/TheTable.js
11:15:10 AM:   Line 3:49:  'Space' is defined but never used         no-unused-vars
11:15:10 AM:   Line 12:3:  'UserOutlined' is defined but never used  no-unused-vars
11:15:10 AM:   Line 21:8:  'UploadFile' is defined but never used    no-unused-vars
11:15:10 AM: src/components/forms/Compra.js
11:15:10 AM:   Line 10:3:  'Switch' is defined but never used   no-unused-vars
11:15:10 AM:   Line 11:3:  'Tooltip' is defined but never used  no-unused-vars
11:15:10 AM: src/components/forms/Filter.js
11:15:10 AM:   Line 3:24:  'Input' is defined but never used  no-unused-vars
11:15:10 AM: src/components/forms/Login.js
11:15:10 AM:   Line 1:17:  'useState' is defined but never used  no-unused-vars
11:15:10 AM: src/context/User.context.js
11:15:10 AM:   Line 16:9:  'navigate' is assigned a value but never used  no-unused-vars
11:15:10 AM: src/pages/Login.js
11:15:10 AM:   Line 2:10:  'Link' is defined but never used                                                                                                                                                no-unused-vars
11:15:10 AM:   Line 2:29:  'redirect' is defined but never used                                                                                                                                            no-unused-vars
11:15:10 AM:   Line 20:5:  'setUserData' is assigned a value but never used                                                                                                                                no-unused-vars
11:15:10 AM:   Line 48:6:  React Hook useEffect has missing dependencies: 'navigate', 'setUserMessage', 'userMessage.message', and 'userMessage.type'. Either include them or remove the dependency array  react-hooks/exhaustive-deps
11:15:10 AM: src/pages/Main.js
11:15:10 AM:   Line 30:31:  'setClearTableSelection' is assigned a value but never used  no-unused-vars
11:15:10 AM: ​
11:15:10 AM:   "build.command" failed                                        
11:15:10 AM: ────────────────────────────────────────────────────────────────
11:15:10 AM: ​
11:15:12 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:15:10 AM:   Error message
11:15:10 AM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
11:15:10 AM: ​
11:15:10 AM:   Error location
11:15:10 AM:   In Build command from Netlify app:
11:15:10 AM:   npm run build
11:15:10 AM: ​
11:15:10 AM:   Resolved config
11:15:10 AM:   build:
11:15:10 AM:     base: /opt/build/repo/client
11:15:10 AM:     command: npm run build
11:15:10 AM:     commandOrigin: ui
11:15:10 AM:     environment:
11:15:10 AM:       - REACT_APP_API
11:15:10 AM:       - REACT_APP_AUTH
11:15:10 AM:       - REACT_APP_LANG
11:15:10 AM:       - REACT_APP_LOGO
11:15:10 AM:       - REACT_APP_SHOWLANG
11:15:10 AM:     publish: /opt/build/repo/client/build
11:15:10 AM:     publishOrigin: ui
11:15:11 AM: Caching artifacts
11:15:11 AM: Started saving node modules
11:15:11 AM: Finished saving node modules
11:15:11 AM: Started saving build plugins
11:15:11 AM: Finished saving build plugins
11:15:11 AM: Started saving corepack cache
11:15:11 AM: Finished saving corepack cache
11:15:11 AM: Started saving pip cache
11:15:11 AM: Finished saving pip cache
11:15:11 AM: Started saving emacs cask dependencies
11:15:11 AM: Finished saving emacs cask dependencies
11:15:11 AM: Started saving maven dependencies
11:15:11 AM: Finished saving maven dependencies
11:15:11 AM: Started saving boot dependencies
11:15:11 AM: Finished saving boot dependencies
11:15:11 AM: Started saving rust rustup cache
11:15:11 AM: Finished saving rust rustup cache
11:15:11 AM: Started saving go dependencies
11:15:11 AM: Finished saving go dependencies
11:15:12 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:15:12 AM: Failing build: Failed to build site
11:15:12 AM: Finished processing build request in 1m31.067s

Was able to find the problem.

It was treating warnings as error hence the build error. Added the Env Variable CI=false and it build successfully.

1 Like

Thanks for sharing your solution with the community! (: