Home
Support Forums

"build.command" failed -- already tried many solutions but still can't get pass

Site name: gallant-dijkstra-ea30fa

I can build local successfully. Tried clear cache and deploy, and searched the problem extensively and still haven’t found one worked.

Please take a look at my error message – would really appreciate some help here. Cheers!

11:02:06 PM:   Netlify Build                                                 
11:02:06 PM: ────────────────────────────────────────────────────────────────
11:02:06 PM: ​
11:02:06 PM: ❯ Version
11:02:06 PM:   @netlify/build 26.1.0
11:02:06 PM: ​
11:02:06 PM: ❯ Flags
11:02:06 PM:   baseRelDir: true
11:02:06 PM:   buildId: 61dc49a40bcdce000711d132
11:02:06 PM:   deployId: 61dc49a40bcdce000711d134
11:02:06 PM: ​
11:02:06 PM: ❯ Current directory
11:02:06 PM:   /opt/build/repo
11:02:06 PM: ​
11:02:06 PM: ❯ Config file
11:02:06 PM:   No config file was defined: using default values.
11:02:06 PM: ​
11:02:06 PM: ❯ Context
11:02:06 PM:   production
11:02:06 PM: ​
11:02:06 PM: ────────────────────────────────────────────────────────────────
11:02:06 PM:   1. Build command from Netlify app                             
11:02:06 PM: ────────────────────────────────────────────────────────────────
11:02:06 PM: ​
11:02:06 PM: $ CI='' npm run build
11:02:06 PM: > portfolio@0.1.0 build /opt/build/repo
11:02:06 PM: > react-scripts build
11:02:08 PM: Creating an optimized production build...
11:02:21 PM: Failed to compile.
11:02:21 PM: 
11:02:21 PM: Module.createRequire is not a function
11:02:21 PM: npm ERR! code ELIFECYCLE
11:02:21 PM: npm ERR! errno 1
11:02:21 PM: npm ERR! portfolio@0.1.0 build: `react-scripts build`
11:02:21 PM: npm ERR! Exit status 1
11:02:21 PM: npm ERR!
11:02:21 PM: npm ERR! Failed at the portfolio@0.1.0 build script.
11:02:21 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
11:02:21 PM: npm ERR! A complete log of this run can be found in:
11:02:21 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-01-10T15_02_21_458Z-debug.log
11:02:21 PM: ​
11:02:21 PM: ────────────────────────────────────────────────────────────────
11:02:21 PM:   "build.command" failed                                        
11:02:21 PM: ────────────────────────────────────────────────────────────────
11:02:21 PM: ​
11:02:21 PM:   Error message
11:02:21 PM:   Command failed with exit code 1: CI='' npm run build
11:02:21 PM: ​
11:02:21 PM:   Error location
11:02:21 PM:   In Build command from Netlify app:
11:02:21 PM:   CI='' npm run build
11:02:21 PM: ​
11:02:21 PM:   Resolved config
11:02:21 PM:   build:
11:02:21 PM:     command: CI='' npm run build
11:02:21 PM:     commandOrigin: ui
11:02:21 PM:     publish: /opt/build/repo/build
11:02:21 PM:     publishOrigin: ui
11:02:21 PM: Caching artifacts
11:02:21 PM: Started saving node modules
11:02:21 PM: Finished saving node modules
11:02:21 PM: Started saving build plugins
11:02:21 PM: Finished saving build plugins
11:02:21 PM: Started saving pip cache
11:02:21 PM: Finished saving pip cache
11:02:21 PM: Started saving emacs cask dependencies
11:02:22 PM: Finished saving emacs cask dependencies
11:02:22 PM: Started saving maven dependencies
11:02:22 PM: Finished saving maven dependencies
11:02:22 PM: Started saving boot dependencies
11:02:22 PM: Finished saving boot dependencies
11:02:22 PM: Started saving rust rustup cache
11:02:22 PM: Finished saving rust rustup cache
11:02:22 PM: Started saving go dependencies
11:02:23 PM: Finished saving go dependencies
11:02:27 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:02:27 PM: Creating deploy upload records
11:02:27 PM: Failing build: Failed to build site
11:02:27 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
11:02:27 PM: Finished processing build request in 3m40.551441744s```

hi there, the above lines indicate the problem - looks like you are trying to run the wrong command.

please see further information from this thread - do know that the command needs to be formatted exactly as indicated, including spaces etc, in order to work properly :slight_smile:

if this still does not work, please do paste any new/changed build errors you receive!

Hi Perry, thanks for your reply. It still doesn’t work for me either CI=true npm run build or CI= npm run build, it returns the same error message. :frowning:

5:37:29 PM: ────────────────────────────────────────────────────────────────
5:37:29 PM:   1. Build command from Netlify app                             
5:37:29 PM: ────────────────────────────────────────────────────────────────
5:37:29 PM: ​
5:37:29 PM: $ CI=true npm run build
5:37:29 PM: > portfolio@0.1.0 build /opt/build/repo
5:37:29 PM: > react-scripts build
5:37:31 PM: Creating an optimized production build...
5:37:43 PM: Failed to compile.
5:37:43 PM: 
5:37:43 PM: Module.createRequire is not a function
5:37:43 PM: npm ERR! code ELIFECYCLE
5:37:43 PM: npm ERR! errno 1
5:37:43 PM: npm ERR! portfolio@0.1.0 build: `react-scripts build`
5:37:43 PM: npm ERR! Exit status 1
5:37:43 PM: npm ERR!
5:37:43 PM: npm ERR! Failed at the portfolio@0.1.0 build script.
5:37:43 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
5:37:43 PM: npm ERR! A complete log of this run can be found in:
5:37:43 PM: npm ERR!     /opt/buildhome/.npm/_logs/2022-01-11T09_37_43_204Z-debug.log
5:37:43 PM: ​
5:37:43 PM: ────────────────────────────────────────────────────────────────
5:37:43 PM:   "build.command" failed                                        
5:37:43 PM: ────────────────────────────────────────────────────────────────
5:37:43 PM: ​
5:37:43 PM:   Error message
5:37:43 PM:   Command failed with exit code 1: CI=true npm run build
5:37:43 PM: ​
5:37:43 PM:   Error location
5:37:43 PM:   In Build command from Netlify app:
5:37:43 PM:   CI=true npm run build
5:37:43 PM: ​
5:37:43 PM:   Resolved config
5:37:43 PM:   build:
5:37:43 PM:     command: CI=true npm run build
5:37:43 PM:     commandOrigin: ui
5:37:43 PM:     publish: /opt/build/repo/build
5:37:43 PM:     publishOrigin: ui
5:37:43 PM: Caching artifacts
5:37:43 PM: Started saving node modules
5:37:43 PM: Finished saving node modules
5:37:43 PM: Started saving build plugins
5:37:43 PM: Finished saving build plugins
5:37:43 PM: Started saving pip cache
5:37:43 PM: Finished saving pip cache
5:37:43 PM: Started saving emacs cask dependencies
5:37:43 PM: Finished saving emacs cask dependencies
5:37:43 PM: Started saving maven dependencies
5:37:43 PM: Finished saving maven dependencies
5:37:43 PM: Started saving boot dependencies
5:37:43 PM: Finished saving boot dependencies
5:37:43 PM: Started saving rust rustup cache
5:37:43 PM: Finished saving rust rustup cache
5:37:43 PM: Started saving go dependencies
5:37:45 PM: Finished saving go dependencies
5:37:49 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:37:49 PM: Creating deploy upload records
5:37:49 PM: Failing build: Failed to build site
5:37:49 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
5:37:49 PM: Finished processing build request in 3m41.014022406s```

Hi @dazyang

This is the reason for the failure.

What version of node.js is the build using?

Node version is v16.13.0

Are you using eslint v8+ and/or node-sass?

Reference

Hi @coelmay Yes, I’m using node-sass (^6.0.1), and it is using Create React App’s default "eslintConfig": { "extends": "react-app"}.

Without seeing the code @dazyang I can only make guesses. Are you able to share the repository?

Yeah, sure, thanks for taking the time to help. I’m currently reconstructing my portfolio website, here is the repo

Thanks @dazyang.

I cloned the repository and was able to build without issue on macOS running node.js v16.13.1. I committed this without change to a new repository and deployed to elastic-knuth-b522aa (see deploy log.)

I assume you are deploying the master branch. Can you spot any differences between the deploy log above the last unsuccessful deploy from your repository? Can you share the link to it?

That’s so bizarre! Yes, deploying master. This is my last unsuccessful deploy log

I see this in your log

10:46:11 PM: Downloading and installing node v10.24.1...
10:46:11 PM: Downloading https://nodejs.org/dist/v10.24.1/node-v10.24.1-linux-x64.tar.xz...
10:46:11 PM: Computing checksum with sha256sum
10:46:12 PM: Checksums matched!
10:46:14 PM: Now using node v10.24.1 (npm v6.14.12)

Netlify pins the node version to avoid breaking builds (which can happen with major version changes.) As your site was originally using v10, it is pinned.

This is breaking the build as per one of the previous links I posted, Module.createRequire needs node.js v14+.

You can change this by adding an .nvmrc file (i.e node -v > .nvmrc in the root of the project and commit this file) or by using the NODE_VERSION environment variable either in the Netilfy UI (see example image below) or via a netlify.toml file in the root of the repository with

[build.environment]
  NODE_VERSION = "v16.13.2"

2 Likes

Oh man, thank you soooo much for your help and explained the problem @coelmay! I have successfully deployed. You are awesome!

1 Like