Command failed with exit code 127: gatsby build

Hi there,

I’m some issue deploying my site.

I’ve tried changing the build commands in my package.json to npm run build but I’m still getting the same error I do with gatsby build.

7:42:24 PM: Build ready to start
7:42:25 PM: build-image version: d84c79427e8f83c1ba17bcdd7b3fe38059376b68
7:42:25 PM: build-image tag: v3.6.1
7:42:25 PM: buildbot version: 44655717ddf0e7bd7f856f5b1154254de54b1d80
7:42:25 PM: Fetching cached dependencies
7:42:25 PM: Failed to fetch cache, continuing with build
7:42:25 PM: Starting to prepare the repo for build
7:42:26 PM: No cached dependencies found. Cloning fresh repo
7:42:26 PM: git clone git@github.com:samadjei/netlify-gatsby-portfolio
7:42:27 PM: Preparing Git Reference refs/heads/main
7:42:29 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'src/public ’ versus ‘public’ in the Netlify UI
7:42:29 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: ‘src/y’ versus ‘y’ in the Netlify UI
7:42:29 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'gatsby build ’ versus ‘CI= npm run build’ in the Netlify UI
7:42:29 PM: Starting build script
7:42:29 PM: Installing dependencies
7:42:29 PM: Python version set to 2.7
7:42:30 PM: v12.18.0 is already installed.
7:42:31 PM: Now using node v12.18.0 (npm v6.14.4)
7:42:31 PM: Started restoring cached build plugins
7:42:31 PM: Finished restoring cached build plugins
7:42:31 PM: Attempting ruby version 2.7.1, read from environment
7:42:32 PM: Using ruby version 2.7.1
7:42:32 PM: Using PHP version 5.6
7:42:32 PM: Started restoring cached go cache
7:42:32 PM: Finished restoring cached go cache
7:42:32 PM: go version go1.14.4 linux/amd64
7:42:32 PM: go version go1.14.4 linux/amd64
7:42:32 PM: Installing missing commands
7:42:32 PM: Verify run directory
7:42:34 PM: ​
7:42:34 PM: ────────────────────────────────────────────────────────────────
7:42:34 PM: Netlify Build
7:42:34 PM: ────────────────────────────────────────────────────────────────
7:42:34 PM: ​
7:42:34 PM: ❯ Version
7:42:34 PM: @netlify/build 8.3.0
7:42:34 PM: ​
7:42:34 PM: ❯ Flags
7:42:34 PM: deployId: 60170820a99944000790125b
7:42:34 PM: mode: buildbot
7:42:34 PM: ​
7:42:34 PM: ❯ Current directory
7:42:34 PM: /opt/build/repo/src
7:42:34 PM: ​
7:42:34 PM: ❯ Config file
7:42:34 PM: /opt/build/repo/netlify.toml
7:42:34 PM: ​
7:42:34 PM: ❯ Context
7:42:34 PM: production
7:42:34 PM: ​
7:42:34 PM: ────────────────────────────────────────────────────────────────
7:42:34 PM: 1. build.command from netlify.toml
7:42:34 PM: ────────────────────────────────────────────────────────────────
7:42:34 PM: ​
7:42:34 PM: $ gatsby build
7:42:34 PM: bash: gatsby: command not found
7:42:34 PM: ​
7:42:34 PM: ────────────────────────────────────────────────────────────────
7:42:34 PM: “build.command” failed
7:42:34 PM: ────────────────────────────────────────────────────────────────
7:42:34 PM: ​
7:42:34 PM: Error message
7:42:34 PM: Command failed with exit code 127: gatsby build
7:42:34 PM: ​
7:42:34 PM: Error location
7:42:34 PM: In build.command from netlify.toml:
7:42:34 PM: gatsby build
7:42:34 PM: ​
7:42:34 PM: Resolved config
7:42:34 PM: build:
7:42:34 PM: base: /opt/build/repo/src
7:42:34 PM: command: 'gatsby build ’
7:42:34 PM: commandOrigin: config
7:42:34 PM: functions: /opt/build/repo/src/y
7:42:34 PM: publish: '/opt/build/repo/src/public ’
7:42:34 PM: Caching artifacts
7:42:34 PM: Started saving build plugins
7:42:34 PM: Finished saving build plugins
7:42:34 PM: Started saving pip cache
7:42:34 PM: Finished saving pip cache
7:42:34 PM: Started saving emacs cask dependencies
7:42:34 PM: Finished saving emacs cask dependencies
7:42:34 PM: Started saving maven dependencies
7:42:34 PM: Finished saving maven dependencies
7:42:34 PM: Started saving boot dependencies
7:42:34 PM: Finished saving boot dependencies
7:42:34 PM: Started saving rust rustup cache
7:42:34 PM: Finished saving rust rustup cache
7:42:34 PM: Started saving go dependencies
7:42:34 PM: Finished saving go dependencies
7:42:36 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:42:36 PM: Failing build: Failed to build site
7:42:36 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
7:42:36 PM: Finished processing build request in 11.194515505s

Here is the build script from my package.json
“scripts”: {
“build”: “npm run 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! → https://gatsby.dev/unit-testing” && exit 1”
},
“repository”: {
“type”: “git”,
“url”: “GitHub - gatsbyjs/gatsby-starter-default: The default Gatsby starter
},
“bugs”: {
“url”: “Issues · gatsbyjs/gatsby · GitHub
}

My build settings

Do you have gatsby in your package.json?

2 Likes

Hi there, yes I have gatsby in my package.json

{
“name”: “gatsby-starter-default”,
“private”: true,
“description”: “A simple starter to get up and developing quickly with Gatsby”,
“version”: “0.1.0”,
“author”: “Samuel Adjei info.samadjei@gmail.com”,
“dependencies”: {
@react-icons/all-files”: “^4.1.0”,
“gatsby”: “^2.26.1”,
“gatsby-image”: “^2.9.0”,
“gatsby-plugin-manifest”: “^2.6.1”,
“gatsby-plugin-offline”: “^3.4.0”,
“gatsby-plugin-react-helmet”: “^3.8.0”,
“gatsby-plugin-sass”: “^3.0.0”,
“gatsby-plugin-sharp”: “^2.12.0”,
“gatsby-plugin-webfonts”: “^1.1.4”,
“gatsby-source-filesystem”: “^2.9.0”,
“gatsby-source-strapi”: “0.0.12”,
“gatsby-transformer-sharp”: “^2.10.0”,
“hamburgers”: “^1.1.3”,
“node-sass”: “^5.0.0”,
“prop-types”: “^15.7.2”,
“react”: “^16.12.0”,
“react-dom”: “^16.12.0”,
“react-helmet”: “^6.1.0”,
“react-icons”: “^4.1.0”,
“react-markdown”: “^5.0.3”,
“sharp”: “^0.27.0”
},
“devDependencies”: {
“prettier”: “2.2.1”
},
“keywords”: [
“gatsby”
],
“license”: “0BSD”,
“scripts”: {
“build”: “npm run 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! → https://gatsby.dev/unit-testing” && exit 1”
},
“repository”: {
“type”: “git”,
“url”: “GitHub - gatsbyjs/gatsby-starter-default: The default Gatsby starter
},
“bugs”: {
“url”: “Issues · gatsbyjs/gatsby · GitHub
}
}

Looks like there are errors in your package.json which prevents the build step from installing your dependencies. Take a look at the format and test script entries, they both contain " (double quote) inside the string. I tried it locally and it installed correctly when fixed.

Also, your build script in package.json should probably be gatsby instead of npm run build. In this case it seems the build system is picking up a build command from netlify.toml.

2 Likes

Hey thank you for your response,

The double quotes are fine as they are being escaped (copy and paste didn’t show the ).

I changed the build command to gatsby build and redeployed it but I got this error.

Here is my folder structure

Here is my build settings:

hi there, do you have a directory called public in your repo? if not, add one.

1 Like

Hi apologies, i just edited the message with the correct screenshot. And yes i do.

i think we can’t find public because it is inside of site. :thinking:

can you move it up a level and see if that fixes things?

1 Like

TBH i’m not sure how to do that :no_mouth:. I tried removing public form the gitignore file and deploying but I got the same issue.

Change publish path to site/public

1 Like

No luck
8:05:46 PM: Build ready to start
8:05:47 PM: build-image version: d84c79427e8f83c1ba17bcdd7b3fe38059376b68
8:05:47 PM: build-image tag: v3.6.1
8:05:47 PM: buildbot version: a0f5a242397f47e25a65cd8b1de9758023166a1b
8:05:47 PM: Building without cache
8:05:47 PM: Starting to prepare the repo for build
8:05:48 PM: No cached dependencies found. Cloning fresh repo
8:05:48 PM: git clone git@github.com:samadjei/netlify-gatsby-portfolio
8:05:50 PM: Preparing Git Reference refs/heads/main
8:05:51 PM: Failing build: Failed to parse configuration
8:05:51 PM: Failed during stage ‘Reading and parsing configuration files’: Base directory does not exist: /opt/build/repo/site: exit status 1
8:05:51 PM: Finished processing build request in 4.195238763s

hi there, please try the following settings:

repo: keep as is
base directory: leave it blank
build command: leave as is
publish directory: site/public
deploy log: leave as is
builds: active

1 Like

Hey there,

I managed to solve the issue. I removed deleted my git repo and netlify instance - redid the deployment and its now working. Thank you all for your help. I really appreciate it :slight_smile:

1 Like