React app compiles locally successfully but build fails in Netlify deploy

Netlify site name: https://freelance-marketing.netlify.app/
Issue: My React app loads successfully locally with no error messages; however, the build fails in Netlify.

Initially, I received the following log with build error “Error: error:0308010C:digital envelope routines::unsupported”. See below:

5:11:40 PM: build-image version: 7635f63deb4beb249d857cc5c9c7eb78d4fd4316 (focal)
5:11:40 PM: buildbot version: 7635f63deb4beb249d857cc5c9c7eb78d4fd4316
5:11:40 PM: Fetching cached dependencies
5:11:40 PM: Starting to download cache of 235.9MB
5:11:43 PM: Finished downloading cache in 2.532s
5:11:43 PM: Starting to extract cache
5:11:49 PM: Finished extracting cache in 6.007s
5:11:49 PM: Finished fetching cache in 8.584s
5:11:49 PM: Starting to prepare the repo for build
5:11:49 PM: Preparing Git Reference refs/heads/master
5:11:50 PM: Parsing package.json dependencies
5:11:51 PM: Starting build script
5:11:51 PM: Installing dependencies
5:11:51 PM: Python version set to 2.7
5:11:51 PM: Started restoring cached Node.js version
5:11:52 PM: Finished restoring cached Node.js version
5:11:52 PM: Downloading and installing node v18.7.0...
5:11:52 PM: Downloading https://nodejs.org/dist/v18.7.0/node-v18.7.0-linux-x64.tar.xz...
5:11:53 PM: Computing checksum with sha256sum
5:11:53 PM: Checksums matched!
5:11:55 PM: Now using node v18.7.0 (npm v8.15.0)
5:11:55 PM: Enabling Node.js Corepack
5:11:55 PM: Started restoring cached build plugins
5:11:55 PM: Finished restoring cached build plugins
5:11:55 PM: Attempting Ruby version 2.7.1, read from environment
5:11:55 PM: Started restoring cached Ruby version
5:11:55 PM: Finished restoring cached Ruby version
5:11:56 PM: Using Ruby version 2.7.1
5:11:56 PM: Using PHP version 8.0
5:11:56 PM: Started restoring cached corepack dependencies
5:11:56 PM: mv: cannot move '/opt/build/cache/.node/corepack' to '/opt/buildhome/.node/corepack': No such file or directory
5:11:56 PM: Finished restoring cached corepack dependencies
5:11:56 PM: Started restoring cached yarn cache
5:11:58 PM: Finished restoring cached yarn cache
5:11:59 PM: Installing Yarn version 1.22.4
5:11:59 PM: Preparing yarn@1.22.4 for immediate activation...
5:11:59 PM: No yarn workspaces detected
5:11:59 PM: Started restoring cached node modules
5:11:59 PM: Finished restoring cached node modules
5:11:59 PM: Installing npm packages using Yarn version 1.22.4
5:12:00 PM: yarn install v1.22.4
5:12:00 PM: [1/5] Validating package.json...
5:12:00 PM: [2/5] Resolving packages...
5:12:00 PM: [3/5] Fetching packages...
5:12:00 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
5:12:00 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
5:12:00 PM: info fsevents@1.2.12: The platform "linux" is incompatible with this module.
5:12:00 PM: info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
5:12:01 PM: [4/5] Linking dependencies...
5:12:01 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
5:12:01 PM: warning " > mini-css-extract-plugin@1.6.0" has unmet peer dependency "webpack@^4.4.0 || ^5.0.0".
5:12:01 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" 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".
5:12:03 PM: [5/5] Building fresh packages...
5:12:03 PM: Done in 3.74s.
5:12:03 PM: npm packages installed using Yarn
5:12:04 PM: Started restoring cached go cache
5:12:04 PM: Finished restoring cached go cache
5:12:04 PM: Installing Go version 1.14.4 (requested 1.14.4)
5:12:08 PM: unset GOOS;
5:12:08 PM: unset GOARCH;
5:12:08 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64';
5:12:08 PM: export PATH="/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64/bin:${PATH}";
5:12:08 PM: go version >&2;
5:12:08 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.14.4.linux.amd64.env"
5:12:08 PM: go version go1.14.4 linux/amd64
5:12:08 PM: Detected 1 framework(s)
5:12:08 PM: "create-react-app" at version "3.4.1"
5:12:08 PM: Installing missing commands
5:12:08 PM: Verify run directory
5:12:08 PM: Section completed: initializing
5:12:10 PM: ​
5:12:10 PM:   Netlify Build                                                 
5:12:10 PM: ────────────────────────────────────────────────────────────────
5:12:10 PM: ​
5:12:10 PM: ❯ Version
5:12:10 PM:   @netlify/build 29.5.1
5:12:10 PM: ​
5:12:10 PM: ❯ Flags
5:12:10 PM:   baseRelDir: true
5:12:10 PM:   buildId: 63d9bc4921d57e0008fc0212
5:12:10 PM:   deployId: 63d9bc4921d57e0008fc0214
5:12:10 PM: ​
5:12:10 PM: ❯ Current directory
5:12:10 PM:   /opt/build/repo
5:12:10 PM: ​
5:12:10 PM: ❯ Config file
5:12:10 PM:   No config file was defined: using default values.
5:12:10 PM: ​
5:12:10 PM: ❯ Context
5:12:10 PM:   production
5:12:10 PM: ​
5:12:10 PM:   1. Build command from Netlify app                             
5:12:10 PM: ────────────────────────────────────────────────────────────────
5:12:10 PM: ​
5:12:10 PM: $ yarn build
5:12:10 PM: yarn run v1.22.4
5:12:10 PM: $ CI= react-scripts build
5:12:10 PM: Creating an optimized production build...
5:12:11 PM: Error: error:0308010C:digital envelope routines::unsupported
5:12:11 PM:     at new Hash (node:internal/crypto/hash:71:19)
5:12:11 PM:     at Object.createHash (node:crypto:133:10)
5:12:11 PM:     at module.exports (/opt/build/repo/node_modules/webpack/lib/util/createHash.js:135:53)
5:12:11 PM:     at NormalModule._initBuildHash (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:417:16)
5:12:11 PM:     at handleParseError (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:471:10)
5:12:11 PM:     at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:503:5
5:12:11 PM:     at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:358:12
5:12:11 PM:     at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:373:3
5:12:11 PM:     at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:214:10)
5:12:11 PM:     at iterateNormalLoaders (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:221:10)
5:12:11 PM: /opt/build/repo/node_modules/react-scripts/scripts/build.js:19
5:12:11 PM:   throw err;
5:12:11 PM:   ^
5:12:11 PM: Error: error:0308010C:digital envelope routines::unsupported
5:12:11 PM:     at new Hash (node:internal/crypto/hash:71:19)
5:12:11 PM:     at Object.createHash (node:crypto:133:10)
5:12:11 PM:     at module.exports (/opt/build/repo/node_modules/webpack/lib/util/createHash.js:135:53)
5:12:11 PM:     at NormalModule._initBuildHash (/opt/build/repo/node_modules/webpack/lib/NormalModule.js:417:16)
5:12:11 PM:     at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:452:10
5:12:11 PM:     at /opt/build/repo/node_modules/webpack/lib/NormalModule.js:323:13
5:12:11 PM:     at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:367:11
5:12:11 PM:     at /opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:233:18
5:12:11 PM:     at context.callback (/opt/build/repo/node_modules/loader-runner/lib/LoaderRunner.js:111:13)
5:12:11 PM:     at /opt/build/repo/node_modules/babel-loader/lib/index.js:59:103 {
5:12:11 PM:   opensslErrorStack: [ 'error:03000086:digital envelope routines::initialization error' ],
5:12:11 PM:   library: 'digital envelope routines',
5:12:11 PM:   reason: 'unsupported',
5:12:11 PM:   code: 'ERR_OSSL_EVP_UNSUPPORTED'
5:12:11 PM: }
5:12:11 PM: Node.js v18.7.0
5:12:11 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
5:12:11 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
5:12:11 PM: ​
5:12:11 PM:   "build.command" failed                                        
5:12:11 PM: ────────────────────────────────────────────────────────────────
5:12:11 PM: ​
5:12:11 PM:   Error message
5:12:11 PM:   Command failed with exit code 1: yarn build (https://ntl.fyi/exit-code-1)
5:12:11 PM: ​
5:12:11 PM:   Error location
5:12:11 PM:   In Build command from Netlify app:
5:12:11 PM:   yarn build
5:12:11 PM: ​
5:12:11 PM:   Resolved config
5:12:11 PM:   build:
5:12:11 PM:     command: yarn build
5:12:11 PM:     commandOrigin: ui
5:12:11 PM:     environment:
5:12:11 PM:       - NODE_VERSION
5:12:11 PM:     publish: /opt/build/repo/build
5:12:11 PM:     publishOrigin: ui
5:12:11 PM: Caching artifacts
5:12:11 PM: Started saving node modules
5:12:11 PM: Finished saving node modules
5:12:11 PM: Started saving build plugins
5:12:11 PM: Finished saving build plugins
5:12:11 PM: Started saving corepack cache
5:12:11 PM: Finished saving corepack cache
5:12:11 PM: Started saving yarn cache
5:12:14 PM: Finished saving yarn cache
5:12:14 PM: Started saving pip cache
5:12:14 PM: Finished saving pip cache
5:12:14 PM: Started saving emacs cask dependencies
5:12:14 PM: Finished saving emacs cask dependencies
5:12:14 PM: Started saving maven dependencies
5:12:14 PM: Finished saving maven dependencies
5:12:14 PM: Started saving boot dependencies
5:12:14 PM: Finished saving boot dependencies
5:12:14 PM: Started saving rust rustup cache
5:12:14 PM: Finished saving rust rustup cache
5:12:14 PM: Started saving go dependencies
5:12:14 PM: Finished saving go dependencies
5:12:16 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:12:16 PM: Failing build: Failed to build site
5:12:16 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:12:16 PM: Finished processing build request in 36.298s

I then referenced this related forum and updated my build script from "CI= react-scripts build" to "NODE_OPTIONS='--openssl-legacy-provider' react-scripts build". But, now I’m getting a new error message and I’m not sure how to proceed:

5:49:53 PM: Waiting for other deploys from your team to complete. Check the queue: https://app.netlify.com/teams/jmychou2/builds
5:50:40 PM: build-image version: 7635f63deb4beb249d857cc5c9c7eb78d4fd4316 (focal)
5:50:40 PM: buildbot version: 7635f63deb4beb249d857cc5c9c7eb78d4fd4316
5:50:40 PM: Fetching cached dependencies
5:50:40 PM: Starting to download cache of 235.9MB
5:50:41 PM: Finished downloading cache in 841ms
5:50:41 PM: Starting to extract cache
5:50:43 PM: Finished extracting cache in 2.709s
5:50:43 PM: Finished fetching cache in 3.601s
5:50:43 PM: Starting to prepare the repo for build
5:50:44 PM: Preparing Git Reference refs/heads/master
5:50:44 PM: Parsing package.json dependencies
5:50:46 PM: Starting build script
5:50:46 PM: Installing dependencies
5:50:46 PM: Python version set to 2.7
5:50:46 PM: Started restoring cached Node.js version
5:50:47 PM: Finished restoring cached Node.js version
5:50:47 PM: Downloading and installing node v18.7.0...
5:50:47 PM: Downloading https://nodejs.org/dist/v18.7.0/node-v18.7.0-linux-x64.tar.xz...
5:50:47 PM: Computing checksum with sha256sum
5:50:47 PM: Checksums matched!
5:50:49 PM: Now using node v18.7.0 (npm v8.15.0)
5:50:49 PM: Enabling Node.js Corepack
5:50:50 PM: Started restoring cached build plugins
5:50:50 PM: Finished restoring cached build plugins
5:50:50 PM: Attempting Ruby version 2.7.1, read from environment
5:50:50 PM: Started restoring cached Ruby version
5:50:50 PM: Finished restoring cached Ruby version
5:50:50 PM: Using Ruby version 2.7.1
5:50:50 PM: Using PHP version 8.0
5:50:50 PM: Started restoring cached corepack dependencies
5:50:50 PM: mv: cannot move '/opt/build/cache/.node/corepack' to '/opt/buildhome/.node/corepack': No such file or directory
5:50:50 PM: Finished restoring cached corepack dependencies
5:50:50 PM: Started restoring cached yarn cache
5:50:52 PM: Finished restoring cached yarn cache
5:50:53 PM: Installing Yarn version 1.22.4
5:50:53 PM: Preparing yarn@1.22.4 for immediate activation...
5:50:53 PM: No yarn workspaces detected
5:50:53 PM: Started restoring cached node modules
5:50:53 PM: Finished restoring cached node modules
5:50:54 PM: Installing npm packages using Yarn version 1.22.4
5:50:54 PM: yarn install v1.22.4
5:50:54 PM: [1/5] Validating package.json...
5:50:54 PM: [2/5] Resolving packages...
5:50:54 PM: [3/5] Fetching packages...
5:50:55 PM: info fsevents@2.1.2: The platform "linux" is incompatible with this module.
5:50:55 PM: info "fsevents@2.1.2" is an optional dependency and failed compatibility check. Excluding it from installation.
5:50:55 PM: info fsevents@1.2.12: The platform "linux" is incompatible with this module.
5:50:55 PM: info "fsevents@1.2.12" is an optional dependency and failed compatibility check. Excluding it from installation.
5:50:55 PM: [4/5] Linking dependencies...
5:50:55 PM: warning " > @testing-library/user-event@7.2.1" has unmet peer dependency "@testing-library/dom@>=5".
5:50:55 PM: warning " > mini-css-extract-plugin@1.6.0" has unmet peer dependency "webpack@^4.4.0 || ^5.0.0".
5:50:55 PM: warning "react-scripts > @typescript-eslint/eslint-plugin > tsutils@3.17.1" 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".
5:50:57 PM: [5/5] Building fresh packages...
5:50:58 PM: Done in 3.89s.
5:50:58 PM: npm packages installed using Yarn
5:50:58 PM: Started restoring cached go cache
5:50:58 PM: Finished restoring cached go cache
5:50:58 PM: Installing Go version 1.14.4 (requested 1.14.4)
5:51:02 PM: unset GOOS;
5:51:02 PM: unset GOARCH;
5:51:02 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64';
5:51:02 PM: export PATH="/opt/buildhome/.gimme/versions/go1.14.4.linux.amd64/bin:${PATH}";
5:51:02 PM: go version >&2;
5:51:02 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.14.4.linux.amd64.env"
5:51:02 PM: go version go1.14.4 linux/amd64
5:51:02 PM: Detected 1 framework(s)
5:51:02 PM: "create-react-app" at version "3.4.1"
5:51:02 PM: Installing missing commands
5:51:02 PM: Verify run directory
5:51:02 PM: Section completed: initializing
5:51:03 PM: ​
5:51:03 PM:   Netlify Build                                                 
5:51:03 PM: ────────────────────────────────────────────────────────────────
5:51:03 PM: ​
5:51:03 PM: ❯ Version
5:51:03 PM:   @netlify/build 29.5.1
5:51:03 PM: ​
5:51:03 PM: ❯ Flags
5:51:03 PM:   baseRelDir: true
5:51:03 PM:   buildId: 63d9c541206c171e5826a602
5:51:03 PM:   deployId: 63d9c541206c171e5826a604
5:51:03 PM: ​
5:51:03 PM: ❯ Current directory
5:51:03 PM:   /opt/build/repo
5:51:03 PM: ​
5:51:03 PM: ❯ Config file
5:51:03 PM:   No config file was defined: using default values.
5:51:03 PM: ​
5:51:03 PM: ❯ Context
5:51:03 PM:   production
5:51:03 PM: ​
5:51:03 PM:   1. Build command from Netlify app                             
5:51:03 PM: ────────────────────────────────────────────────────────────────
5:51:03 PM: ​
5:51:03 PM: $ yarn build
5:51:04 PM: yarn run v1.22.4
5:51:04 PM: $ NODE_OPTIONS='--openssl-legacy-provider' react-scripts build
5:51:05 PM: Creating an optimized production build...
5:51:06 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:06 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:07 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:08 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:09 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:09 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:09 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:09 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:09 PM: Browserslist: caniuse-lite is outdated. Please run the following command: `npx browserslist --update-db`
5:51:09 PM: 
5:51:09 PM: Treating warnings as errors because process.env.CI = true.
5:51:09 PM: Most CI servers set it automatically.
5:51:09 PM: 
5:51:09 PM: Failed to compile.
5:51:09 PM: 
5:51:09 PM: ./src/App.js
5:51:09 PM:   Line 11:8:   'ContactForm' is defined but never used  no-unused-vars
5:51:09 PM:   Line 12:8:   'Footer' is defined but never used       no-unused-vars
5:51:09 PM:   Line 16:10:  'Spring' is defined but never used       no-unused-vars
5:51:09 PM: ./src/Sections/AboutMe.js
5:51:09 PM:   Line 19:33:  img elements must have an alt prop, either with meaningful text, or an empty string for decorative images  jsx-a11y/alt-text
5:51:09 PM: error Command failed with exit code 1. (https://ntl.fyi/exit-code-1)
5:51:09 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
5:51:09 PM: ​
5:51:09 PM:   "build.command" failed                                        
5:51:09 PM: ────────────────────────────────────────────────────────────────
5:51:09 PM: ​
5:51:09 PM:   Error message
5:51:09 PM:   Command failed with exit code 1: yarn build (https://ntl.fyi/exit-code-1)
5:51:09 PM: ​
5:51:09 PM:   Error location
5:51:09 PM:   In Build command from Netlify app:
5:51:09 PM:   yarn build
5:51:09 PM: ​
5:51:09 PM:   Resolved config
5:51:09 PM:   build:
5:51:09 PM:     command: yarn build
5:51:09 PM:     commandOrigin: ui
5:51:09 PM:     environment:
5:51:09 PM:       - NODE_VERSION
5:51:09 PM:     publish: /opt/build/repo/build
5:51:09 PM:     publishOrigin: ui
5:51:10 PM: Caching artifacts
5:51:10 PM: Started saving node modules
5:51:10 PM: Finished saving node modules
5:51:10 PM: Started saving build plugins
5:51:10 PM: Finished saving build plugins
5:51:10 PM: Started saving corepack cache
5:51:10 PM: Finished saving corepack cache
5:51:10 PM: Started saving yarn cache
5:51:12 PM: Finished saving yarn cache
5:51:12 PM: Started saving pip cache
5:51:12 PM: Finished saving pip cache
5:51:12 PM: Started saving emacs cask dependencies
5:51:12 PM: Finished saving emacs cask dependencies
5:51:12 PM: Started saving maven dependencies
5:51:12 PM: Finished saving maven dependencies
5:51:12 PM: Started saving boot dependencies
5:51:12 PM: Finished saving boot dependencies
5:51:12 PM: Started saving rust rustup cache
5:51:12 PM: Finished saving rust rustup cache
5:51:12 PM: Started saving go dependencies
5:51:12 PM: Finished saving go dependencies
5:51:13 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:51:13 PM: Failing build: Failed to build site
5:51:13 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:51:13 PM: Finished processing build request in 33.463s

Here are my build settings:

Thanks for reading!

Your original build script had CI= react where the CI= had no value, and thus evaluated to false.

Your new build script doesn’t have a value for CI= and the default is true.

The warnings you have are now being treated as errors and causing your build to fail.

I can’t advise on the rest of the command, but you likely want something along the lines of…

NODE_OPTIONS='--openssl-legacy-provider' CI= react-scripts build

Thank you for your quick and thorough response! That fixed it.

@codecaviette100 glad to hear nathan’s solution helped you fix your build. (: