Gatsby deployment error on run build: “Failed during stage ‘building site’: build script returned non-zero exit code: 137”

I’ve just built a new site using a Gatsby starter, and it’s supposed to deploy from my GitHub repo GitHub - VincenzoDelre/Portfolio .

The deploy failed with both commands
“scripts”: {
“build”: “gatsby build”,

“Failed during stage ‘building site’: build script returned non-zero exit code: 2”

“scripts”: {
“build”: "npm run build ",

“Failed during stage ‘building site’: build script returned non-zero exit code: 137”

json.lock
{
“name”: “gatsby-starter-default”,
“private”: true,
“description”: “A simple starter to get up and developing quickly with Gatsby”,
“version”: “0.1.0”,
“author”: “Kyle Mathews mathews.kyle@gmail.com”,
“dependencies”: {
@emotion/react”: “^11.4.1”,
@emotion/styled”: “^11.3.0”,
“gatsby”: “^3.12.1”,
“gatsby-background-image”: “^1.5.3”,
“gatsby-cli”: “^4.5.2”,
“gatsby-plugin-emotion”: “^6.12.0”,
“gatsby-plugin-gatsby-cloud”: “^2.11.0”,
“gatsby-plugin-image”: “^1.12.0”,
“gatsby-plugin-manifest”: “^3.12.0”,
“gatsby-plugin-offline”: “^4.12.0”,
“gatsby-plugin-react-helmet”: “^4.12.0”,
“gatsby-plugin-sass”: “^4.13.0”,
“gatsby-plugin-sharp”: “^3.12.0”,
“gatsby-plugin-smoothscroll”: “^1.2.0”,
“gatsby-source-datocms”: “^2.6.16”,
“gatsby-source-filesystem”: “^3.12.0”,
“gatsby-transformer-sharp”: “^3.12.0”,
“prop-types”: “^15.7.2”,
“react”: “^17.0.1”,
“react-dom”: “^17.0.2”,
“react-helmet”: “^6.1.0”,
“swiper”: “^7.0.5”
},
“devDependencies”: {
“prettier”: “2.3.2”
},
“keywords”: [
“gatsby”
],
“license”: “0BSD”,
“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! → Unit Testing” && exit 1”
},
“repository”: {
“type”: “git”,
“url”: “GitHub - gatsbyjs/gatsby-starter-default: The default Gatsby starter
},
“bugs”: {
“url”: “Issues · gatsbyjs/gatsby · GitHub
}
}

Hi @Vincenzo_Delre

There a several posts around code 137 which may help you.

If none of these help solve the issue, can you link to a deploy log where this error occurs.

1 Like

As described on the original post, I’ve tried to change the build command on the pakage.json and on the netlify build page as npm run buil or gatsby build…
this is the log. Thanks

9:51:42 AM: 2. Build command from Netlify app
9:51:42 AM: ────────────────────────────────────────────────────────────────
9:51:42 AM: ​
9:51:42 AM: $ gatsby build
9:51:48 AM: success open and validate gatsby-configs, load plugins - 2.008s
9:51:48 AM: error “gatsby-plugin-manifest” threw an error while running the onPreInit lifecycle:
9:51:48 AM: ENOENT: no such file or directory, open ‘src/images/gatsby-icon.png’
9:51:48 AM: 144 |
9:51:48 AM: 145 | if (pluginOptions.cache_busting_mode !== “none” && pluginOptions.icon) {
9:51:48 AM: > 146 | pluginOptions.cacheDigest = (0, _gatsbyCoreUtils.createContentDigest)(fs.readFileSync(pluginOptions.icon));
9:51:48 AM: | ^
9:51:48 AM: 147 | }
9:51:48 AM: 148 | };
9:51:48 AM: 149 |
9:51:48 AM:
9:51:48 AM:
9:51:48 AM: Error: ENOENT: no such file or directory, open ‘src/images/gatsby-icon.png’
9:51:48 AM:
9:51:48 AM: - node:fs:585 Object.openSync
9:51:48 AM: node:fs:585:3
9:51:48 AM:
9:51:48 AM: - node:fs:453 Object.readFileSync
9:51:48 AM: node:fs:453:35
9:51:48 AM:
9:51:48 AM: - gatsby-node.js:146 Object.exports.onPreInit
9:51:48 AM: [repo]/[gatsby-plugin-manifest]/gatsby-node.js:146:78
9:51:48 AM:
9:51:48 AM: - api-runner-node.js:434 runAPI
9:51:48 AM: [repo]/[gatsby]/src/utils/api-runner-node.js:434:22
9:51:48 AM:
9:51:48 AM: - api-runner-node.js:590 Promise.catch.decorateEvent.pluginName
9:51:48 AM: [repo]/[gatsby]/src/utils/api-runner-node.js:590:13
9:51:48 AM:
9:51:48 AM: - debuggability.js:384 Promise._execute
9:51:48 AM: [repo]/[bluebird]/js/release/debuggability.js:384:9
9:51:48 AM:
9:51:48 AM: - promise.js:518 Promise._resolveFromExecutor
9:51:48 AM: [repo]/[bluebird]/js/release/promise.js:518:18
9:51:48 AM:
9:51:48 AM: - promise.js:103 new Promise
9:51:48 AM: [repo]/[bluebird]/js/release/promise.js:103:10
9:51:48 AM:
9:51:48 AM: - api-runner-node.js:588
9:51:48 AM: [repo]/[gatsby]/src/utils/api-runner-node.js:588:16
9:51:48 AM:
9:51:48 AM: - util.js:16 tryCatcher
9:51:48 AM: [repo]/[bluebird]/js/release/util.js:16:23
9:51:48 AM:
9:51:48 AM: - reduce.js:166 Object.gotValue
9:51:48 AM: [repo]/[bluebird]/js/release/reduce.js:166:18
9:51:48 AM:
9:51:48 AM: - reduce.js:155 Object.gotAccum
9:51:48 AM: [repo]/[bluebird]/js/release/reduce.js:155:25
9:51:48 AM:
9:51:48 AM: - util.js:16 Object.tryCatcher
9:51:48 AM: [repo]/[bluebird]/js/release/util.js:16:23
9:51:48 AM:
9:51:48 AM: - promise.js:547 Promise._settlePromiseFromHandler
9:51:48 AM: [repo]/[bluebird]/js/release/promise.js:547:31
9:51:48 AM:
9:51:48 AM: - promise.js:604 Promise._settlePromise
9:51:48 AM: [repo]/[bluebird]/js/release/promise.js:604:18
9:51:48 AM:
9:51:48 AM: - promise.js:649 Promise._settlePromise0
9:51:48 AM: [repo]/[bluebird]/js/release/promise.js:649:10
9:51:48 AM:
9:51:48 AM:
9:51:48 AM: not finished onPreInit - 0.190s
9:51:48 AM: ​
9:51:48 AM: ────────────────────────────────────────────────────────────────
9:51:48 AM: “build.command” failed
9:51:48 AM: ────────────────────────────────────────────────────────────────
9:51:48 AM: ​
9:51:48 AM: Error message
9:51:48 AM: Command failed with exit code 1: gatsby build
9:51:48 AM: ​
9:51:48 AM: Error location
9:51:48 AM: In Build command from Netlify app:
9:51:48 AM: gatsby build
9:51:48 AM: ​
9:51:48 AM: Resolved config
9:51:48 AM: build:
9:51:48 AM: command: gatsby build
9:51:48 AM: commandOrigin: ui
9:51:48 AM: publish: /opt/build/repo/public
9:51:48 AM: publishOrigin: ui
9:51:48 AM: plugins:
9:51:48 AM: - inputs: {}
9:51:48 AM: origin: ui
9:51:48 AM: package: ‘@netlify/plugin-gatsby’
9:51:48 AM: Caching artifacts
9:51:48 AM: Started saving node modules
9:51:48 AM: Finished saving node modules
9:51:48 AM: Started saving build plugins
9:51:48 AM: Finished saving build plugins
9:51:48 AM: Started saving pip cache
9:51:48 AM: Finished saving pip cache
9:51:48 AM: Started saving emacs cask dependencies
9:51:48 AM: Finished saving emacs cask dependencies
9:51:48 AM: Started saving maven dependencies
9:51:49 AM: Finished saving maven dependencies
9:51:49 AM: Started saving boot dependencies
9:51:49 AM: Finished saving boot dependencies
9:51:49 AM: Started saving rust rustup cache
9:51:49 AM: Finished saving rust rustup cache
9:51:49 AM: Started saving go dependencies
9:51:49 AM: Finished saving go dependencies
9:51:51 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:51:51 AM: Creating deploy upload records
9:51:51 AM: Failing build: Failed to build site
9:51:51 AM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
9:51:51 AM: Finished processing build request in 2m29.781126198s

The reason for the failure is described in the message below

In the gatsby-config.js is the line:

icon: `src/images/gatsby-icon.png`, // This path is relative to the root of the site.

but as per the message above, this file does not exist so the build is failing.

1 Like

Thanks. Appreciated. There was an error with this file because it was on the root src/images/gatsby-icon.png. The file has been changed and the deploy was built correctly after fixing others errors.

1 Like