Gatsby Command failed with exit code 127: gatsby build

Hi guys,

I’m having trouble to try to make my test website work. I have built on gatsby but when I tried to deploy on netfly I got the following error.

I was following this video below.

time is 4:31:07.

My website is https://affectionate-brahmagupta-a1629d.netlify.app/
on the “Building Setting” I change to:
Build command: gatsby build
Publish Directory: public

    12:36:19 AM: Build ready to start
    12:36:21 AM: build-image version: be42e453d6c8f171cc2f654acc29c0a8b60e6d93
    12:36:21 AM: build-image tag: v3.7.1
    12:36:21 AM: buildbot version: 449a896d650f66a48d6924703527235917156153
    12:36:21 AM: Fetching cached dependencies
    12:36:21 AM: Starting to download cache of 723.5KB
    12:36:21 AM: Finished downloading cache in 147.953818ms
    12:36:21 AM: Starting to extract cache
    12:36:21 AM: Finished extracting cache in 21.73405ms
    12:36:21 AM: Finished fetching cache in 170.313612ms
    12:36:21 AM: Starting to prepare the repo for build
    12:36:22 AM: Preparing Git Reference refs/heads/main
    12:36:24 AM: Starting build script
    12:36:24 AM: Installing dependencies
    12:36:24 AM: Python version set to 2.7
    12:36:25 AM: v12.18.0 is already installed.
    12:36:26 AM: Now using node v12.18.0 (npm v6.14.4)
    12:36:26 AM: Started restoring cached build plugins
    12:36:26 AM: Finished restoring cached build plugins
    12:36:26 AM: Attempting ruby version 2.7.1, read from environment
    12:36:27 AM: Using ruby version 2.7.1
    12:36:27 AM: Using PHP version 5.6
    12:36:27 AM: Started restoring cached go cache
    12:36:27 AM: Finished restoring cached go cache
    12:36:27 AM: go version go1.14.4 linux/amd64
    12:36:27 AM: go version go1.14.4 linux/amd64
    12:36:27 AM: Installing missing commands
    12:36:27 AM: Verify run directory
    12:36:29 AM: ​
    12:36:29 AM: ────────────────────────────────────────────────────────────────
    12:36:29 AM:   Netlify Build                                                 
    12:36:29 AM: ────────────────────────────────────────────────────────────────
    12:36:29 AM: ​
    12:36:29 AM: ❯ Version
    12:36:29 AM:   @netlify/build 10.2.3
    12:36:29 AM: ​
    12:36:29 AM: ❯ Flags
    12:36:29 AM:   deployId: 606cf0736fc5cf00955d2224
    12:36:29 AM: ​
    12:36:29 AM: ❯ Current directory
    12:36:29 AM:   /opt/build/repo
    12:36:29 AM: ​
    12:36:29 AM: ❯ Config file
    12:36:29 AM:   No config file was defined: using default values.
    12:36:29 AM: ​
    12:36:29 AM: ❯ Context
    12:36:29 AM:   production
    12:36:29 AM: ​
    12:36:29 AM: ────────────────────────────────────────────────────────────────
    12:36:29 AM:   1. Build command from Netlify app                             
    12:36:29 AM: ────────────────────────────────────────────────────────────────
    12:36:29 AM: ​
    12:36:29 AM: $ gatsby build
    12:36:29 AM: bash: gatsby: command not found
    12:36:29 AM: ​
    12:36:29 AM: ────────────────────────────────────────────────────────────────
    12:36:29 AM:   "build.command" failed                                        
    12:36:29 AM: ────────────────────────────────────────────────────────────────
    12:36:29 AM: ​
    12:36:29 AM:   Error message
    12:36:29 AM:   Command failed with exit code 127: gatsby build
    12:36:29 AM: ​
    12:36:29 AM:   Error location
    12:36:29 AM:   In Build command from Netlify app:
    12:36:29 AM:   gatsby build
    12:36:29 AM: ​
    12:36:29 AM:   Resolved config
    12:36:29 AM:   build:
    12:36:29 AM:     command: gatsby build
    12:36:29 AM:     commandOrigin: ui
    12:36:29 AM:     environment:
    12:36:29 AM:       - CONTENTFUL_ACCESS_TOKEN
    12:36:29 AM:       - CONTENTFUL_SPACE_ID
    12:36:29 AM:     publish: /opt/build/repo/public
    12:36:30 AM: Caching artifacts
    12:36:30 AM: Started saving build plugins
    12:36:30 AM: Finished saving build plugins
    12:36:30 AM: Started saving pip cache
    12:36:30 AM: Finished saving pip cache
    12:36:30 AM: Started saving emacs cask dependencies
    12:36:30 AM: Finished saving emacs cask dependencies
    12:36:30 AM: Started saving maven dependencies
    12:36:30 AM: Finished saving maven dependencies
    12:36:30 AM: Started saving boot dependencies
    12:36:30 AM: Finished saving boot dependencies
    12:36:30 AM: Started saving rust rustup cache
    12:36:30 AM: Finished saving rust rustup cache
    12:36:30 AM: Started saving go dependencies
    12:36:30 AM: Finished saving go dependencies
    12:36:32 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
    12:36:32 AM: Failing build: Failed to build site
    12:36:32 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2
    12:36:32 AM: Finished processing build request in 11.39196151s

Thanks
:slight_smile:

howdy, could you post your package.json please? i bet there is some dependency needed that we can’t find for some reason!

Hi Perry,
thanks for your reply!

See below.

{
  "name": "gatsby-starter-hello-world",
  "private": true,
  "description": "A simplified bare-bones starter for Gatsby",
  "version": "0.1.0",
  "license": "0BSD",
  "scripts": {
    "build": "gatsby build",
    "develop": "env-cmd -f .env 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! -> https://gatsby.dev/unit-testing\" && exit 1"
  },
  "dependencies": {
    "@contentful/rich-text-react-renderer": "^14.1.2",
    "@contentful/rich-text-types": "^14.1.2",
    "formik": "^2.2.6",
    "gatsby": "^3.1.0",
    "gatsby-plugin-postcss": "^4.0.0",
    "gatsby-plugin-react-helmet": "^4.2.0",
    "gatsby-plugin-sass": "^4.0.2",
    "gatsby-plugin-sharp": "^3.0.1",
    "gatsby-remark-images": "^4.0.0",
    "gatsby-remark-relative-images": "^2.0.2",
    "gatsby-source-contentful": "^5.0.3",
    "gatsby-source-filesystem": "^3.0.0",
    "gatsby-transformer-remark": "^3.0.0",
    "node-sass": "^5.0.0",
    "postcss-cli": "^8.3.1",
    "postcss-flexbugs-fixes": "^5.0.2",
    "postcss-loader": "^5.2.0",
    "react": "^17.0.1",
    "react-dom": "^17.0.1",
    "react-helmet": "^6.1.0",
    "yup": "^0.32.9"
  },
  "devDependencies": {
    "env-cmd": "^10.1.0",
    "postcss": "8.2.8",
    "prettier": "2.2.1"
  },
  "peerDependencies": {
    "postcss": "^8.2.8"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/gatsbyjs/gatsby-starter-hello-world"
  },
  "bugs": {
    "url": "https://github.com/gatsbyjs/gatsby/issues"
  }
}



hi there, i think that many of the things that you are listing under “dependencies” (available at runtime) should actually be under “devdependencies” which are needed to build the project. Maybe you can compare your package.json file with the one created in the lesson to find out which you need where?

Hi there,

I have changed a little bit the project I mean is not exactly the same as the tutorial I have mixed what I have learned from others videos as well so my “dependecies” will be different. I don’t now what to do.

Thanks

Hi There,

Is it possible try to deploy the website narrowing down the plugin to see which one is causing the problem?

Thanks
Neto

i would try making the dependencies and devdependencies of your site match and have both sections include everything. and then try deploying - that might work, and then you can try to narrow down which thing is causing the issue.

Hi there,

i saw here maybe is some misconfiguration, see below I’m not sure how to point the currect directory.

I was seeing the error again and looks like the netlify is not finding the “build command” because the way is wrong, but I don’t know what to put there.

Thanks
Neto

hi there, let’s take a step back. Would you work through this guide first, please? there are some basics we’ll need to get covered before we can troubleshoot the fine points :slight_smile:

Hi Perry,
So I could make work, but now I have another issue is on the “gatsby-remark-relative-images” plugin is showing up this error below on netlify

9:19:49 PM: The "path" argument must be of type string. Received undefined
9:19:49 PM: 
9:19:49 PM: 
9:19:49 PM:   Error: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type s  tring. Received undefined
9:19:49 PM:   
9:19:49 PM:   - validators.js:120 validateString
9:19:49 PM:     internal/validators.js:120:11
9:19:49 PM:   
9:19:49 PM:   - on-create-node.js:15 Object.exports.onCreateNode
9:19:49 PM:     [repo]/[gatsby-remark-relative-images]/dist/on-create-node.js:15:42
9:19:49 PM:   
9:19:49 PM:   - api-runner-node.js:434 runAPI
9:19:49 PM:     [repo]/[gatsby]/src/utils/api-runner-node.js:434:22
9:19:49 PM:   
9:19:49 PM:   - api-runner-node.js:585 Promise.catch.decorateEvent.pluginName
9:19:49 PM:     [repo]/[gatsby]/src/utils/api-runner-node.js:585:13
9:19:49 PM:   
9:19:49 PM:   - debuggability.js:384 Promise._execute
9:19:49 PM:     [repo]/[bluebird]/js/release/debuggability.js:384:9
9:19:49 PM:   
9:19:49 PM:   - promise.js:518 Promise._resolveFromExecutor
9:19:49 PM:     [repo]/[bluebird]/js/release/promise.js:518:18
9:19:49 PM:   
9:19:49 PM:   - promise.js:103 new Promise
9:19:49 PM:     [repo]/[bluebird]/js/release/promise.js:103:10
9:19:49 PM:   
9:19:49 PM:   - api-runner-node.js:583 
9:19:49 PM:     [repo]/[gatsby]/src/utils/api-runner-node.js:583:16
9:19:49 PM:   
9:19:49 PM:   - util.js:16 tryCatcher
9:19:49 PM:     [repo]/[bluebird]/js/release/util.js:16:23
9:19:49 PM:   
9:19:49 PM:   - reduce.js:166 Object.gotValue
9:19:49 PM:     [repo]/[bluebird]/js/release/reduce.js:166:18
9:19:49 PM:   
9:19:49 PM:   - reduce.js:155 Object.gotAccum
9:19:49 PM:     [repo]/[bluebird]/js/release/reduce.js:155:25
9:19:49 PM:   
9:19:49 PM:   - util.js:16 Object.tryCatcher
9:19:49 PM:     [repo]/[bluebird]/js/release/util.js:16:23
9:19:49 PM:   
9:19:49 PM:   - promise.js:547 Promise._settlePromiseFromHandler
9:19:49 PM:     [repo]/[bluebird]/js/release/promise.js:547:31
9:19:49 PM:   
9:19:49 PM:   - promise.js:604 Promise._settlePromise
9:19:49 PM:     [repo]/[bluebird]/js/release/promise.js:604:18
9:19:49 PM:   
9:19:49 PM:   - promise.js:649 Promise._settlePromise0
9:19:49 PM:     [repo]/[bluebird]/js/release/promise.js:649:10

On the develop mode I had the same error but when I update the plugin such as npm i gatsby-remark-relative-images@latest it worked, but in Netlify it didn’t.

Thanks
Neto

Hey there, @NetoSena :wave:

Looks like this thread has been quiet for a few days :slight_smile: Are you still encountering issues with “gatsby-remark-relative-images”? If so, what have you tried since you last posted?

Let us know!

Hi there,
I got the solution, the problem it was that I was using different version of node so when I tried to deploy on netlitly I was getting this error above.

So I had to just run this command below node -v > .nvmrc to netlify use my version of node js and then it worked perfectly.

Thanks
Neto

1 Like

Thanks for coming back and sharing this with us! This will be beneficial for future Forums members who encounter something similar. :netliconfetti: