Build fails on deploy but not dev. Just updated to create-react-app 5

I just updated to create-react-app 5.0.0. There aren’t any warnings or problems when I build locally, but I am getting errors when trying to deploy.

My build command has CI turned off:

CI= npm run build

Here is the deploy log:

9:04:34 AM: Build ready to start
9:04:55 AM: build-image version: 73def8bb10593b9b818f44989a75ea508018ccb7 (focal)
9:04:55 AM: build-image tag: v4.5.2
9:04:55 AM: buildbot version: 2bc1f2bdf0b9d9b409a93865d875253a16c2438b
9:04:55 AM: Building without cache
9:04:55 AM: Starting to prepare the repo for build
9:04:55 AM: Git LFS enabled
9:04:55 AM: No cached dependencies found. Cloning fresh repo
9:04:55 AM: git lfs clone https://github.com/team-refcode/refcode.org
9:05:04 AM: Preparing Git Reference refs/heads/master
9:05:04 AM: Parsing package.json dependencies
9:05:05 AM: Starting build script
9:05:05 AM: Installing dependencies
9:05:05 AM: Python version set to 2.7
9:05:06 AM: Downloading and installing node v10.24.1...
9:05:06 AM: Downloading https://nodejs.org/dist/v10.24.1/node-v10.24.1-linux-x64.tar.xz...
9:05:07 AM: Computing checksum with sha256sum
9:05:07 AM: Checksums matched!
9:05:09 AM: Now using node v10.24.1 (npm v6.14.12)
9:05:09 AM: Started restoring cached build plugins
9:05:09 AM: Finished restoring cached build plugins
9:05:09 AM: Attempting ruby version 2.6.2, read from environment
9:05:10 AM: Required ruby-2.6.2 is not installed - installing.
9:05:10 AM: Searching for binary rubies, this might take some time.
9:05:11 AM: Found remote file https://rvm_io.global.ssl.fastly.net/binaries/ubuntu/20.04/x86_64/ruby-2.6.2.tar.bz2
9:05:11 AM: Checking requirements for ubuntu.
9:05:11 AM: Requirements installation successful.
9:05:11 AM: ruby-2.6.2 - #configure
9:05:11 AM: ruby-2.6.2 - #download
9:05:12 AM: ruby-2.6.2 - #validate archive
9:05:17 AM: ruby-2.6.2 - #extract
9:05:20 AM: ruby-2.6.2 - #validate binary
9:05:21 AM: ruby-2.6.2 - #setup
9:05:22 AM: ruby-2.6.2 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.6.2@global
9:05:22 AM: ruby-2.6.2 - #importing gemset /opt/buildhome/.rvm/gemsets/global.gems........................................
9:05:22 AM: ruby-2.6.2 - #generating global wrappers........
9:05:22 AM: ruby-2.6.2 - #gemset created /opt/buildhome/.rvm/gems/ruby-2.6.2
9:05:22 AM: ruby-2.6.2 - #importing gemsetfile /opt/buildhome/.rvm/gemsets/default.gems evaluated to empty gem list
9:05:23 AM: ruby-2.6.2 - #generating default wrappers........
9:05:24 AM: Using /opt/buildhome/.rvm/gems/ruby-2.6.2
9:05:24 AM: Using ruby version 2.6.2
9:05:24 AM: Using PHP version 8.0
9:05:24 AM: Started restoring cached node modules
9:05:24 AM: Finished restoring cached node modules
9:05:25 AM: Installing NPM modules using NPM version 6.14.12
9:05:53 AM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!
9:05:53 AM: > sharp@0.28.3 install /opt/build/repo/node_modules/sharp
9:05:53 AM: > (node install/libvips && node install/dll-copy && prebuild-install) || (node install/can-compile && node-gyp rebuild && node install/dll-copy)
9:05:55 AM: sharp: Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.10.6/libvips-8.10.6-linux-x64.tar.br
9:05:57 AM: > core-js@3.20.3 postinstall /opt/build/repo/node_modules/core-js
9:05:57 AM: > node -e "try{require('./postinstall')}catch(e){}"
9:05:57 AM: > core-js-pure@3.8.3 postinstall /opt/build/repo/node_modules/core-js-pure
9:05:57 AM: > node -e "try{require('./postinstall')}catch(e){}"
9:05:58 AM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.3.2 (node_modules/fsevents):
9:05:58 AM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.3.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
9:05:58 AM: added 1612 packages from 831 contributors and audited 1613 packages in 32.922s
9:06:00 AM: 175 packages are looking for funding
9:06:00 AM:   run `npm fund` for details
9:06:00 AM: found 2 moderate severity vulnerabilities
9:06:00 AM:   run `npm audit fix` to fix them, or `npm audit` for details
9:06:00 AM: NPM modules installed
9:06:00 AM: Started restoring cached go cache
9:06:00 AM: Finished restoring cached go cache
9:06:00 AM: Installing Go version 1.12
9:06:05 AM: unset GOOS;
9:06:05 AM: unset GOARCH;
9:06:05 AM: export GOROOT='/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64';
9:06:05 AM: export PATH="/opt/buildhome/.gimme_cache/versions/go1.12.linux.amd64/bin:${PATH}";
9:06:05 AM: go version >&2;
9:06:05 AM: export GIMME_ENV="/opt/buildhome/.gimme_cache/env/go1.12.linux.amd64.env"
9:06:05 AM: go version go1.12 linux/amd64
9:06:06 AM: Installing missing commands
9:06:06 AM: Verify run directory
9:06:07 AM: ​
9:06:07 AM: ────────────────────────────────────────────────────────────────
9:06:07 AM:   Netlify Build                                                 
9:06:07 AM: ────────────────────────────────────────────────────────────────
9:06:07 AM: ​
9:06:07 AM: ❯ Version
9:06:07 AM:   @netlify/build 26.1.6
9:06:07 AM: ​
9:06:07 AM: ❯ Flags
9:06:07 AM:   baseRelDir: false
9:06:07 AM:   buildId: 61e81a7256bc9f0d0d5344bf
9:06:07 AM:   deployId: 61e81a7256bc9f0d0d5344c1
9:06:07 AM: ​
9:06:07 AM: ❯ Current directory
9:06:07 AM:   /opt/build/repo
9:06:07 AM: ​
9:06:07 AM: ❯ Config file
9:06:07 AM:   No config file was defined: using default values.
9:06:07 AM: ​
9:06:07 AM: ❯ Context
9:06:07 AM:   production
9:06:07 AM: ​
9:06:07 AM: ────────────────────────────────────────────────────────────────
9:06:07 AM:   1. Build command from Netlify app                             
9:06:07 AM: ────────────────────────────────────────────────────────────────
9:06:07 AM: ​
9:06:07 AM: $ CI= npm run build
9:06:08 AM: > refcode-app@0.1.0 prebuild /opt/build/repo
9:06:08 AM: > npm run optimizeimg
9:06:08 AM: > refcode-app@0.1.0 optimizeimg /opt/build/repo
9:06:08 AM: > node imgOptimizer.js
9:07:26 AM: > refcode-app@0.1.0 build /opt/build/repo
9:07:26 AM: > react-scripts build
9:07:28 AM: Creating an optimized production build...
9:07:39 AM: Failed to compile.
9:07:39 AM: 
9:07:39 AM: Module.createRequire is not a function
9:07:39 AM: npm ERR! code ELIFECYCLE
9:07:39 AM: npm ERR! errno 1
9:07:39 AM: npm ERR! refcode-app@0.1.0 build: `react-scripts build`
9:07:39 AM: npm ERR! Exit status 1
9:07:39 AM: npm ERR!
9:07:39 AM: npm ERR! Failed at the refcode-app@0.1.0 build script.
9:07:39 AM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
9:07:39 AM: npm ERR! A complete log of this run can be found in:
9:07:39 AM: npm ERR!     /opt/buildhome/.npm/_logs/2022-01-19T14_07_39_472Z-debug.log
9:07:39 AM: ​
9:07:39 AM: ────────────────────────────────────────────────────────────────
9:07:39 AM:   "build.command" failed                                        
9:07:39 AM: ────────────────────────────────────────────────────────────────
9:07:39 AM: ​
9:07:39 AM:   Error message
9:07:39 AM:   Command failed with exit code 1: CI= npm run build
9:07:39 AM: ​
9:07:39 AM:   Error location
9:07:39 AM:   In Build command from Netlify app:
9:07:39 AM:   CI= npm run build
9:07:39 AM: ​
9:07:39 AM:   Resolved config
9:07:39 AM:   build:
9:07:39 AM:     command: CI= npm run build
9:07:39 AM:     commandOrigin: ui
9:07:39 AM:     environment:
9:07:39 AM:       - GIT_LFS_ENABLED
9:07:39 AM:     publish: /opt/build/repo/build
9:07:39 AM:     publishOrigin: ui
9:07:39 AM: Caching artifacts
9:07:39 AM: Started saving node modules
9:07:39 AM: Finished saving node modules
9:07:39 AM: Started saving build plugins
9:07:39 AM: Finished saving build plugins
9:07:39 AM: Started saving pip cache
9:07:39 AM: Finished saving pip cache
9:07:39 AM: Started saving emacs cask dependencies
9:07:39 AM: Finished saving emacs cask dependencies
9:07:39 AM: Started saving maven dependencies
9:07:39 AM: Finished saving maven dependencies
9:07:39 AM: Started saving boot dependencies
9:07:39 AM: Finished saving boot dependencies
9:07:39 AM: Started saving rust rustup cache
9:07:39 AM: Finished saving rust rustup cache
9:07:40 AM: Started saving go dependencies
9:07:41 AM: Finished saving go dependencies
9:07:44 AM: Cached ruby version 2.6.2
9:07:44 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:07:44 AM: Creating deploy upload records
9:07:44 AM: Failing build: Failed to build site
9:07:44 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
9:07:44 AM: Finished processing build request in 2m49.610038615s

I do see that it says I can review the logs at /opt/buildhome/.npm/_logs/2022-01-19T14_07_39_472Z-debug.log but how do I access that file?

I discovered the answer: Create React App 5 requires a Node version of at least 14. I added a .nvmrc file and it deployed ok.

1 Like

thanks for sharing! this will definitely help others.