Deploy failed - Command failed with exit code 127: gatsby build

I am struggling to get netlify to build. I have searched all the forums and have tried everything I can find. Below is the Deploy Log. Any help would be great. The netlify domain is https://sad-lamport-be7b2e.netlify.app

5:17:29 PM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41
5:17:29 PM: build-image tag: v3.5.0
5:17:29 PM: buildbot version: 92401c20a786cb1d10de411d95c4bfae445aeadc
5:17:29 PM: Building without cache
5:17:29 PM: Starting to prepare the repo for build
5:17:29 PM: No cached dependencies found. Cloning fresh repo
5:17:29 PM: git clone https://github.com/adogam/clearsight
5:17:30 PM: Preparing Git Reference refs/heads/main
5:17:32 PM: Starting build script
5:17:33 PM: Installing dependencies
5:17:33 PM: Python version set to 2.7
5:17:34 PM: v12.18.0 is already installed.
5:17:35 PM: Now using node v12.18.0 (npm v6.14.4)
5:17:35 PM: Started restoring cached build plugins
5:17:35 PM: Finished restoring cached build plugins
5:17:35 PM: Attempting ruby version 2.7.1, read from environment
5:17:37 PM: Using ruby version 2.7.1
5:17:37 PM: Using PHP version 5.6
5:17:37 PM: Started restoring cached node modules
5:17:37 PM: Finished restoring cached node modules
5:17:38 PM: Installing NPM modules using NPM version 6.14.4
5:17:56 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-register/node_modules/core-js
5:17:56 PM: > node -e "try{require('./postinstall')}catch(e){}"
5:17:56 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
5:17:56 PM: > node -e "try{require('./postinstall')}catch(e){}"
5:17:57 PM: npm WARN Invalid name: "Clearsight Vision Health"
5:17:57 PM: npm WARN repo No description
5:17:57 PM: npm WARN repo No repository field.
5:17:57 PM: npm WARN repo No README data
5:17:57 PM: npm WARN repo No license field.
5:17:57 PM: added 100 packages from 82 contributors in 18.023s
5:17:57 PM: 12 packages are looking for funding
5:17:57 PM:   run `npm fund` for details
5:17:57 PM: found 0 vulnerabilities
5:17:57 PM: NPM modules installed
5:17:57 PM: Started restoring cached go cache
5:17:57 PM: Finished restoring cached go cache
5:17:57 PM: go version go1.14.4 linux/amd64
5:17:57 PM: go version go1.14.4 linux/amd64
5:17:57 PM: Installing missing commands
5:17:57 PM: Verify run directory
5:17:59 PM: ​
5:17:59 PM: ┌─────────────────────────────┐
5:17:59 PM: │        Netlify Build        │
5:17:59 PM: └─────────────────────────────┘
5:17:59 PM: ​
5:17:59 PM: ❯ Version
5:17:59 PM:   @netlify/build 5.3.1
5:17:59 PM: ​
5:17:59 PM: ❯ Flags
5:17:59 PM:   deployId: 5fb45a07c1f62c21a357ed9e
5:17:59 PM:   mode: buildbot
5:17:59 PM: ​
5:17:59 PM: ❯ Current directory
5:17:59 PM:   /opt/build/repo
5:17:59 PM: ​
5:17:59 PM: ❯ Config file
5:17:59 PM:   No config file was defined: using default values.
5:17:59 PM: ​
5:17:59 PM: ❯ Context
5:17:59 PM:   production
5:17:59 PM: ​
5:17:59 PM: ┌───────────────────────────────────┐
5:17:59 PM: │ 1. Build command from Netlify app │
5:17:59 PM: └───────────────────────────────────┘
5:17:59 PM: ​
5:17:59 PM: $ gatsby build
5:17:59 PM: bash: gatsby: command not found
5:17:59 PM: ​
5:17:59 PM: ┌─────────────────────────────┐
5:17:59 PM: │   "build.command" failed    │
5:17:59 PM: └─────────────────────────────┘
5:17:59 PM: ​
5:17:59 PM:   Error message
5:17:59 PM:   Command failed with exit code 127: gatsby build
5:17:59 PM: ​
5:17:59 PM:   Error location
5:17:59 PM:   In Build command from Netlify app:
5:17:59 PM:   gatsby build
5:17:59 PM: ​
5:17:59 PM:   Resolved config
5:17:59 PM:   build:
5:17:59 PM:     command: gatsby build
5:17:59 PM:     commandOrigin: ui
5:17:59 PM:     publish: /opt/build/repo/public
5:17:59 PM: Caching artifacts
5:17:59 PM: Started saving node modules
5:17:59 PM: Finished saving node modules
5:17:59 PM: Started saving build plugins
5:17:59 PM: Finished saving build plugins
5:17:59 PM: Started saving pip cache
5:17:59 PM: Finished saving pip cache
5:17:59 PM: Started saving emacs cask dependencies
5:18:00 PM: Finished saving emacs cask dependencies
5:18:00 PM: Started saving maven dependencies
5:18:00 PM: Finished saving maven dependencies
5:18:00 PM: Started saving boot dependencies
5:18:00 PM: Finished saving boot dependencies
5:18:00 PM: Started saving go dependencies
5:18:00 PM: Finished saving go dependencies
5:18:03 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:18:03 PM: Failing build: Failed to build site
5:18:03 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
5:18:03 PM: Finished processing build request in 33.969307221s```

I can see gatsby: command not found. Is gatsby included in your package.json dependencies?

1 Like

Yes! Here are the contents of the file…
{
“name”: “site name”,
“private”: true,
“description”: “site name”,
“version”: “0.1.0”,
“author”: “Adam”,
“bugs”: {
“url”: “https://github.com/gatsbyjs/gatsby/issues
},
“dependencies”: {
“bulma”: “^0.9.1”,
“gatsby”: “^2.24.85”,
“gatsby-image”: “^2.4.21”,
“gatsby-plugin-feed”: “^2.5.19”,
“gatsby-plugin-google-analytics”: “^2.3.19”,
“gatsby-plugin-klaviyo”: “^0.1.2”,
“gatsby-plugin-manifest”: “^2.4.35”,
“gatsby-plugin-offline”: “^3.2.37”,
“gatsby-plugin-react-helmet”: “^3.3.14”,
“gatsby-plugin-sass”: “^2.3.22”,
“gatsby-plugin-sharp”: “^2.6.43”,
“gatsby-plugin-zendesk-configurable-chat”: “^1.0.1”,
“gatsby-remark-copy-linked-files”: “^2.3.19”,
“gatsby-remark-images”: “^3.3.39”,
“gatsby-remark-prismjs”: “^3.5.16”,
“gatsby-remark-responsive-iframe”: “^2.4.17”,
“gatsby-remark-smartypants”: “^2.3.13”,
“gatsby-source-filesystem”: “^2.3.37”,
“gatsby-transformer-remark”: “^2.8.46”,
“gatsby-transformer-sharp”: “^2.5.20”,
“node-sass”: “^4.14.1”,
“prismjs”: “^1.22.0”,
“react”: “^16.12.0”,
“react-dom”: “^16.12.0”,
“react-helmet”: “^5.2.1”,
“typeface-merriweather”: “0.0.72”,
“typeface-montserrat”: “0.0.75”
},
“devDependencies”: {
“prettier”: “2.1.2”
},
“homepage”: “https://github.com/adogam/clearsight-website#readme”,
“keywords”: [
“gatsby”
],
“license”: “0BSD”,
“main”: “n/a”,
“repository”: {
“type”: “git”,
“url”: “git+https://github.com/adogam/clearsight-website”
},
“scripts”: {
“build”: “gatsby build”,
“develop”: “gatsby develop”,
“format”: “prettier --write "**/*.{js,jsx,ts,tsx,json,md}"”,
“start”: “npm run develop”,
“serve”: “gatsby serve”,
“clean”: “gatsby clean”,
“test”: “echo "Write tests! → Link not found - Rebrandly” && exit 1"
}
}

I’m not sure if this is directly related but is this line correct? I’ve checked in my code editor and it throws an error. I don’t think it needs the additional quote marks around **/*.{js,jsx,ts,tsx,json,md}

I didn’t touch that code. It’s right from the Gatsby starter template. I assume it’s right.

1 Like

Fixed! The spaces in the name cause the issue. It fixed that problem and now more problems popped up that need to be fixed.

Thanks!

Netlify is throwing this error now… Any help would be great. Thanks again.

7:18:42 PM: Build ready to start
7:18:44 PM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41
7:18:44 PM: build-image tag: v3.5.0
7:18:44 PM: buildbot version: 92401c20a786cb1d10de411d95c4bfae445aeadc
7:18:44 PM: Fetching cached dependencies
7:18:44 PM: Failed to fetch cache, continuing with build
7:18:44 PM: Starting to prepare the repo for build
7:18:44 PM: No cached dependencies found. Cloning fresh repo
7:18:44 PM: git clone https://github.com/adogam/clearsight
7:18:45 PM: Preparing Git Reference refs/heads/main
7:18:47 PM: Starting build script
7:18:47 PM: Installing dependencies
7:18:47 PM: Python version set to 2.7
7:18:48 PM: v12.18.0 is already installed.
7:18:49 PM: Now using node v12.18.0 (npm v6.14.4)
7:18:49 PM: Started restoring cached build plugins
7:18:49 PM: Finished restoring cached build plugins
7:18:49 PM: Attempting ruby version 2.7.1, read from environment
7:18:50 PM: Using ruby version 2.7.1
7:18:51 PM: Using PHP version 5.6
7:18:51 PM: Started restoring cached node modules
7:18:51 PM: Finished restoring cached node modules
7:18:51 PM: Installing NPM modules using NPM version 6.14.4
7:19:38 PM: > bufferutil@4.0.1 install /opt/build/repo/node_modules/bufferutil
7:19:38 PM: > node-gyp-build
7:19:39 PM: > utf-8-validate@5.0.2 install /opt/build/repo/node_modules/utf-8-validate
7:19:39 PM: > node-gyp-build
7:19:39 PM: > sharp@0.25.4 install /opt/build/repo/node_modules/sharp
7:19:39 PM: > (node install/libvips && node install/dll-copy && prebuild-install --runtime=napi) || (node-gyp rebuild && node install/dll-copy)
7:19:40 PM: info sharp Downloading https://github.com/lovell/sharp-libvips/releases/download/v8.9.1/libvips-8.9.1-linux-x64.tar.gz
7:19:42 PM: > node-sass@4.14.1 install /opt/build/repo/node_modules/node-sass
7:19:42 PM: > node scripts/install.js
7:19:43 PM: Downloading binary from https://github.com/sass/node-sass/releases/download/v4.14.1/linux-x64-72_binding.node
7:19:43 PM: Download complete
7:19:43 PM: Binary saved to /opt/build/repo/node_modules/node-sass/vendor/linux-x64-72/binding.node
7:19:43 PM: Caching binary to /opt/buildhome/.npm/node-sass/4.14.1/linux-x64-72_binding.node
7:19:44 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-polyfill/node_modules/core-js
7:19:44 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:19:44 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-register/node_modules/core-js
7:19:44 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:19:44 PM: > core-js@2.6.11 postinstall /opt/build/repo/node_modules/babel-runtime/node_modules/core-js
7:19:44 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:19:44 PM: > core-js@3.6.5 postinstall /opt/build/repo/node_modules/core-js
7:19:44 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:19:44 PM: > core-js-pure@3.6.5 postinstall /opt/build/repo/node_modules/core-js-pure
7:19:44 PM: > node -e "try{require('./postinstall')}catch(e){}"
7:19:45 PM: > gatsby-telemetry@1.4.1 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-telemetry
7:19:45 PM: > node src/postinstall.js || true
7:19:45 PM: > mozjpeg@7.0.0 postinstall /opt/build/repo/node_modules/mozjpeg
7:19:45 PM: > node lib/install.js
7:19:46 PM:   ✔ mozjpeg pre-build test passed successfully
7:19:46 PM: > pngquant-bin@6.0.0 postinstall /opt/build/repo/node_modules/pngquant-bin
7:19:46 PM: > node lib/install.js
7:19:46 PM:   ✔ pngquant pre-build test passed successfully
7:19:46 PM: > gatsby-cli@2.13.1 postinstall /opt/build/repo/node_modules/gatsby/node_modules/gatsby-cli
7:19:46 PM: > node scripts/postinstall.js
7:19:46 PM: > gatsby@2.26.1 postinstall /opt/build/repo/node_modules/gatsby
7:19:46 PM: > node scripts/postinstall.js
7:19:47 PM: > node-sass@4.14.1 postinstall /opt/build/repo/node_modules/node-sass
7:19:47 PM: > node scripts/build.js
7:19:47 PM: Binary found at /opt/build/repo/node_modules/node-sass/vendor/linux-x64-72/binding.node
7:19:47 PM: Testing binary
7:19:47 PM: Binary is fine
7:19:50 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.13 (node_modules/fsevents):
7:19:50 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.13: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7:19:50 PM: npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/chokidar/node_modules/fsevents):
7:19:50 PM: npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
7:19:50 PM: added 2504 packages from 1337 contributors and audited 2509 packages in 58.432s
7:19:52 PM: 168 packages are looking for funding
7:19:52 PM:   run `npm fund` for details
7:19:52 PM: found 1 low severity vulnerability
7:19:52 PM:   run `npm audit fix` to fix them, or `npm audit` for details
7:19:52 PM: NPM modules installed
7:19:53 PM: Started restoring cached go cache
7:19:53 PM: Finished restoring cached go cache
7:19:53 PM: go version go1.14.4 linux/amd64
7:19:53 PM: go version go1.14.4 linux/amd64
7:19:53 PM: Installing missing commands
7:19:53 PM: Verify run directory
7:19:54 PM: ​
7:19:54 PM: ┌─────────────────────────────┐
7:19:54 PM: │        Netlify Build        │
7:19:54 PM: └─────────────────────────────┘
7:19:54 PM: ​
7:19:54 PM: ❯ Version
7:19:54 PM:   @netlify/build 5.3.1
7:19:54 PM: ​
7:19:54 PM: ❯ Flags
7:19:54 PM:   deployId: 5fb476722f7117000739779b
7:19:54 PM:   mode: buildbot
7:19:54 PM: ​
7:19:54 PM: ❯ Current directory
7:19:54 PM:   /opt/build/repo
7:19:54 PM: ​
7:19:54 PM: ❯ Config file
7:19:54 PM:   No config file was defined: using default values.
7:19:54 PM: ​
7:19:54 PM: ❯ Context
7:19:54 PM:   production
7:19:54 PM: ​
7:19:54 PM: ┌───────────────────────────────────┐
7:19:54 PM: │ 1. Build command from Netlify app │
7:19:54 PM: └───────────────────────────────────┘
7:19:54 PM: ​
7:19:54 PM: $ gatsby build
7:19:57 PM: success open and validate gatsby-configs - 0.041s
7:19:58 PM: success load plugins - 1.196s
7:19:58 PM: success onPreInit - 0.041s
7:19:58 PM: success delete html and css files from previous builds - 0.003s
7:19:58 PM: success initialize cache - 0.006s
7:19:59 PM: success copy gatsby files - 0.032s
7:19:59 PM: success onPreBootstrap - 0.015s
7:19:59 PM: success createSchemaCustomization - 0.165s
7:19:59 PM: success Checking for changed pages - 0.000s
7:19:59 PM: success source and transform nodes - 0.179s
7:20:00 PM: success building schema - 0.532s
7:20:00 PM: info Total nodes: 104, SitePage nodes: 4 (use --verbose for breakdown)
7:20:00 PM: success createPages - 0.039s
7:20:00 PM: success Checking for changed pages - 0.000s
7:20:00 PM: success createPagesStatefully - 0.092s
7:20:00 PM: success update schema - 0.036s
7:20:00 PM: success onPreExtractQueries - 0.000s
7:20:00 PM: success extract queries from components - 0.597s
7:20:00 PM: success write out redirect data - 0.002s
7:20:01 PM: success Build manifest and related icons - 0.258s
7:20:01 PM: success onPostBootstrap - 0.260s
7:20:01 PM: info bootstrap finished - 6.170s
7:20:01 PM: success run static queries - 0.043s - 3/3 69.92/s
7:20:01 PM: warning code block or inline code language not specified in markdown. applying generic code block
7:20:02 PM: success run page queries - 1.321s - 10/10 7.57/s
7:20:02 PM: success write out requires - 0.006s
7:20:22 PM: failed Building production JavaScript and CSS bundles - 19.985s
7:20:22 PM: error Generating JavaScript bundles failed
7:20:22 PM: Can't resolve 'gatsby-legacy-polyfills' in '/opt/build/repo/.cache'
7:20:22 PM: If you're trying to use a package make sure that 'gatsby-legacy-polyfills' is installed. If you're trying to use a local file make sure that the path is correct.
7:20:22 PM: error Generating JavaScript bundles failed
7:20:22 PM: Can't resolve 'gatsby-link' in '/opt/build/repo/.cache'
7:20:22 PM: If you're trying to use a package make sure that 'gatsby-link' is installed. If you're trying to use a local file make sure that the path is correct.
7:20:22 PM: error Generating JavaScript bundles failed
7:20:22 PM: Can't resolve 'gatsby-link' in '/opt/build/repo/.cache'
7:20:22 PM: If you're trying to use a package make sure that 'gatsby-link' is installed. If you're trying to use a local file make sure that the path is correct.
7:20:22 PM: error Generating JavaScript bundles failed
7:20:22 PM: Can't resolve 'gatsby-react-router-scroll' in '/opt/build/repo/.cache'
7:20:22 PM: If you're trying to use a package make sure that 'gatsby-react-router-scroll' is installed. If you're trying to use a local file make sure that the path is correct.
7:20:22 PM: error Generating JavaScript bundles failed
7:20:22 PM: Can't resolve 'gatsby-react-router-scroll' in '/opt/build/repo/.cache'
7:20:22 PM: If you're trying to use a package make sure that 'gatsby-react-router-scroll' is installed. If you're trying to use a local file make sure that the path is correct.
7:20:22 PM: not finished Generating image thumbnails - 21.339s
7:20:22 PM: ​
7:20:22 PM: ┌─────────────────────────────┐
7:20:22 PM: │   "build.command" failed    │
7:20:22 PM: └─────────────────────────────┘
7:20:22 PM: ​
7:20:22 PM:   Error message
7:20:22 PM:   Command failed with exit code 1: gatsby build
7:20:22 PM: ​
7:20:22 PM:   Error location
7:20:22 PM:   In Build command from Netlify app:
7:20:22 PM:   gatsby build
7:20:22 PM: ​
7:20:22 PM:   Resolved config
7:20:22 PM:   build:
7:20:22 PM:     command: gatsby build
7:20:22 PM:     commandOrigin: ui
7:20:22 PM:     publish: /opt/build/repo/public
7:20:22 PM: Caching artifacts
7:20:22 PM: Started saving node modules
7:20:22 PM: Finished saving node modules
7:20:22 PM: Started saving build plugins
7:20:22 PM: Finished saving build plugins
7:20:22 PM: Started saving pip cache
7:20:22 PM: Finished saving pip cache
7:20:22 PM: Started saving emacs cask dependencies
7:20:22 PM: Finished saving emacs cask dependencies
7:20:22 PM: Started saving maven dependencies
7:20:22 PM: Finished saving maven dependencies
7:20:22 PM: Started saving boot dependencies
7:20:22 PM: Finished saving boot dependencies
7:20:22 PM: Started saving go dependencies
7:20:22 PM: Finished saving go dependencies
7:20:25 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:20:25 PM: Failing build: Failed to build site
7:20:25 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
7:20:25 PM: Finished processing build request in 1m41.779843931s

Hi, @adogam. The issue is that gatsby is only installed for your repo directory and not globally so the command is not found when called directly.

The solution is to change the build command from this:

gatsby build

to this:

npm run build

This will use npm to run the script named build which itself is defined in package.json as gatsby build. It work for npm to run this command and because npm will use the locally installed node packages.

The first version gatsby build is looking for gatsby in the locations defined by shell PATH environment variable and it isn’t found there. This will likely be true for all your site builds using node so please keep this in mind for future sites as well.

If that change of the build command to npm run build doesn’t resolve the issue or if there are other questions, please reply anytime.

If you run npm run build locally, you’ll see a list of errors there too. You are missing dependencies. Run the following and it’ll be fixed:

npm i --save gatsby-link gatsby-legacy-polyfills gatsby-react-router-scroll

1 Like