Home
Support Forums

Deploy Failed: "Failed during stage 'building site': Build script returned non-zero exit code: 1"

Hello, I am having an issue with deploying my site to netlify. I am using the sanity-gatsby blog starter. Been tweaking it locally, and everything was working fine. When I committed my changes to my repo, and deployed my site on netlify I got the following errors. I must have done something wrong…I am new to all of this and would greatly appreciate any help. Thank you!


1:27:00 PM: Build ready to start

1:27:02 PM: build-image version: 0582042f4fc261adc7bd8333f34884959c577302

1:27:02 PM: build-image tag: v3.7.6

1:27:02 PM: buildbot version: 25525176e9a3fd4732ec80c06d9af2d602b3de9c

1:27:02 PM: Building without cache

1:27:02 PM: Starting to prepare the repo for build

1:27:03 PM: No cached dependencies found. Cloning fresh repo

1:27:03 PM: git clone git@github.com:mxysaj/launchblog

1:27:06 PM: Preparing Git Reference refs/heads/main

1:27:06 PM: Parsing package.json dependencies

1:27:07 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: '' versus '/' in the Netlify UI

1:27:07 PM: Starting build script

1:27:07 PM: Installing dependencies

1:27:07 PM: Python version set to 2.7

1:27:08 PM: v12.18.0 is already installed.

1:27:09 PM: Now using node v12.18.0 (npm v6.14.4)

1:27:09 PM: Started restoring cached build plugins

1:27:09 PM: Finished restoring cached build plugins

1:27:09 PM: Attempting ruby version 2.7.1, read from environment

1:27:11 PM: Using ruby version 2.7.1

1:27:11 PM: Using PHP version 5.6

1:27:11 PM: Started restoring cached node modules

1:27:11 PM: Finished restoring cached node modules

1:27:11 PM: Installing NPM modules using NPM version 6.14.4

1:27:31 PM: npm WARN read-shrinkwrap This version of npm is compatible with lockfileVersion@1, but package-lock.json was generated for lockfileVersion@2. I'll try to do my best with it!

1:27:31 PM: > sanity-gatsby-blog@1.0.17 postinstall /opt/build/repo

1:27:31 PM: > lerna bootstrap

1:27:31 PM: lerna notice cli v3.22.1

1:27:31 PM: lerna info ci enabled

1:27:31 PM: lerna info Bootstrapping 2 packages

1:27:31 PM: lerna info Installing external dependencies

1:27:32 PM: lerna ERR! npm ci exited 1 in 'blog-with-gatsby-studio'

1:27:32 PM: lerna ERR! npm ci stderr:

1:27:32 PM: npm ERR! cipm can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing.

1:27:32 PM: npm ERR!

1:27:32 PM: npm ERR!

1:27:32 PM: npm ERR! Missing: @sanity/code-input@^2.9.0

1:27:32 PM: npm ERR!

1:27:32 PM: npm ERR! A complete log of this run can be found in:

1:27:32 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-06-15T09_27_32_785Z-debug.log

1:27:32 PM: lerna ERR! npm ci exited 1 in 'blog-with-gatsby-studio'

1:27:32 PM: lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.

1:27:32 PM: npm ERR! code ELIFECYCLE

1:27:32 PM: npm ERR! errno 1

1:27:32 PM: npm ERR! sanity-gatsby-blog@1.0.17 postinstall: `lerna bootstrap`

1:27:32 PM: npm ERR! Exit status 1

1:27:32 PM: npm ERR!

1:27:32 PM: npm ERR! Failed at the sanity-gatsby-blog@1.0.17 postinstall script.

1:27:32 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

1:27:32 PM: npm ERR! A complete log of this run can be found in:

1:27:32 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-06-15T09_27_32_903Z-debug.log

1:27:32 PM: Error during NPM install

1:27:32 PM: Build was terminated: Build script returned non-zero exit code: 1

1:27:32 PM: Creating deploy upload records

1:27:33 PM: Failing build: Failed to build site

1:27:33 PM: Failed during stage 'building site': Build script returned non-zero exit code: 1

1:27:33 PM: Finished processing build request in 30.878369855s

Hi @m_90,

I’d advise to try removing package-lock.json from your repo and retrying to see if it makes a difference.

1 Like

Hi @hrishikesh , thank you for your reply. If I understand you correctly, I should delete the package-lock.json from my repo, commit changes and then retry deploying?

According to the error, yes, it seems like package-lock.json is the offending file (unless you have the other one that the logs mention).

Thank you for your help. I tried removing the file, but no luck. Any idea why?

10:00:38 PM: Build ready to start

10:00:49 PM: build-image version: 0582042f4fc261adc7bd8333f34884959c577302

10:00:49 PM: build-image tag: v3.7.6

10:00:49 PM: buildbot version: 77f6cd099df893d1381a2962ebcc1926e092a904

10:00:49 PM: Fetching cached dependencies

10:00:49 PM: Starting to download cache of 94.3MB

10:00:50 PM: Finished downloading cache in 1.483693903s

10:00:50 PM: Starting to extract cache

10:00:54 PM: Finished extracting cache in 3.667191387s

10:00:54 PM: Finished fetching cache in 5.190936479s

10:00:54 PM: Starting to prepare the repo for build

10:00:55 PM: Preparing Git Reference refs/heads/main

10:00:56 PM: Parsing package.json dependencies

10:00:56 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: '' versus '/' in the Netlify UI

10:00:57 PM: Starting build script

10:00:57 PM: Installing dependencies

10:00:57 PM: Python version set to 2.7

10:00:57 PM: Started restoring cached node version

10:01:00 PM: Finished restoring cached node version

10:01:01 PM: v12.18.0 is already installed.

10:01:01 PM: Now using node v12.18.0 (npm v6.14.4)

10:01:01 PM: Started restoring cached build plugins

10:01:01 PM: Finished restoring cached build plugins

10:01:02 PM: Attempting ruby version 2.7.1, read from environment

10:01:03 PM: Using ruby version 2.7.1

10:01:03 PM: Using PHP version 5.6

10:01:03 PM: Started restoring cached node modules

10:01:03 PM: Finished restoring cached node modules

10:01:04 PM: Started restoring cached go cache

10:01:04 PM: Finished restoring cached go cache

10:01:04 PM: go version go1.14.4 linux/amd64

10:01:04 PM: go version go1.14.4 linux/amd64

10:01:04 PM: Installing missing commands

10:01:04 PM: Verify run directory

10:01:05 PM: ​

10:01:05 PM: ────────────────────────────────────────────────────────────────

10:01:05 PM:   Netlify Build                                                 

10:01:05 PM: ────────────────────────────────────────────────────────────────

10:01:05 PM: ​

10:01:05 PM: ❯ Version

10:01:05 PM:   @netlify/build 12.2.0

10:01:05 PM: ​

10:01:05 PM: ❯ Flags

10:01:05 PM:   deployId: 60c8eaab8dd60f0007855b16

10:01:05 PM: ​

10:01:05 PM: ❯ Current directory

10:01:05 PM:   /opt/build/repo

10:01:05 PM: ​

10:01:05 PM: ❯ Config file

10:01:05 PM:   No config file was defined: using default values.

10:01:05 PM: ​

10:01:05 PM: ❯ Context

10:01:05 PM:   production

10:01:05 PM: ​

10:01:05 PM: ────────────────────────────────────────────────────────────────

10:01:05 PM:   1. Build command from Netlify app                             

10:01:05 PM: ────────────────────────────────────────────────────────────────

10:01:05 PM: ​

10:01:05 PM: $ npm run build

10:01:05 PM: > sanity-gatsby-blog@1.0.17 build /opt/build/repo

10:01:05 PM: > lerna run build --parallel

10:01:05 PM: lerna notice cli v3.22.1

10:01:05 PM: lerna info ci enabled

10:01:06 PM: lerna info Executing command in 2 packages: "npm run build"

10:01:06 PM: blog-with-gatsby-studio: > blog-with-gatsby-studio@1.0.15 build /opt/build/repo/studio

10:01:06 PM: blog-with-gatsby-studio: > sanity build

10:01:06 PM: blog-with-gatsby-web: > blog-with-gatsby-web@1.0.7 build /opt/build/repo/web

10:01:06 PM: blog-with-gatsby-web: > gatsby build

10:01:06 PM: blog-with-gatsby-web: sh: 1: gatsby: not found

10:01:06 PM: blog-with-gatsby-web: npm ERR! code ELIFECYCLE

10:01:06 PM: blog-with-gatsby-web: npm ERR! syscall spawn

10:01:06 PM: blog-with-gatsby-web: npm ERR! file sh

10:01:06 PM: blog-with-gatsby-web: npm ERR! errno ENOENT

10:01:06 PM: blog-with-gatsby-web: npm ERR! blog-with-gatsby-web@1.0.7 build: `gatsby build`

10:01:06 PM: blog-with-gatsby-web: npm ERR! spawn ENOENT

10:01:06 PM: blog-with-gatsby-web: npm ERR!

10:01:06 PM: blog-with-gatsby-web: npm ERR! Failed at the blog-with-gatsby-web@1.0.7 build script.

10:01:06 PM: blog-with-gatsby-web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

10:01:06 PM: blog-with-gatsby-web: npm WARN Local package.json exists, but node_modules missing, did you mean to install?

10:01:06 PM: blog-with-gatsby-web: npm ERR! A complete log of this run can be found in:

10:01:06 PM: blog-with-gatsby-web: npm ERR!     /opt/buildhome/.npm/_logs/2021-06-15T18_01_06_442Z-debug.log

10:01:06 PM: lerna ERR! npm run build exited 1 in 'blog-with-gatsby-web'

10:01:06 PM: lerna ERR! npm run build stdout:

10:01:06 PM: > blog-with-gatsby-web@1.0.7 build /opt/build/repo/web

10:01:06 PM: > gatsby build

10:01:06 PM: lerna ERR! npm run build stderr:

10:01:06 PM: sh: 1: gatsby: not found

10:01:06 PM: npm ERR! code ELIFECYCLE

10:01:06 PM: npm ERR! syscall spawn

10:01:06 PM: npm ERR! file sh

10:01:06 PM: npm ERR! errno ENOENT

10:01:06 PM: npm ERR! blog-with-gatsby-web@1.0.7 build: `gatsby build`

10:01:06 PM: npm ERR! spawn ENOENT

10:01:06 PM: npm ERR!

10:01:06 PM: npm ERR! Failed at the blog-with-gatsby-web@1.0.7 build script.

10:01:06 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

10:01:06 PM: npm WARN Local package.json exists, but node_modules missing, did you mean to install?

10:01:06 PM: npm ERR! A complete log of this run can be found in:

10:01:06 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-06-15T18_01_06_442Z-debug.log

10:01:06 PM: lerna ERR! npm run build exited 1 in 'blog-with-gatsby-web'

10:01:06 PM: lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.

10:01:06 PM: npm ERR! code ELIFECYCLE

10:01:06 PM: npm ERR! errno 1

10:01:06 PM: npm ERR! sanity-gatsby-blog@1.0.17 build: `lerna run build --parallel`

10:01:06 PM: npm ERR! Exit status 1

10:01:06 PM: npm ERR!

10:01:06 PM: npm ERR! Failed at the sanity-gatsby-blog@1.0.17 build script.

10:01:06 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

10:01:06 PM: npm ERR! A complete log of this run can be found in:

10:01:06 PM: npm ERR!     /opt/buildhome/.npm/_logs/2021-06-15T18_01_06_506Z-debug.log

10:01:06 PM: ​

10:01:06 PM: ────────────────────────────────────────────────────────────────

10:01:06 PM:   "build.command" failed                                        

10:01:06 PM: ────────────────────────────────────────────────────────────────

10:01:06 PM: ​

10:01:06 PM:   Error message

10:01:06 PM:   Command failed with exit code 1: npm run build

10:01:06 PM: ​

10:01:06 PM:   Error location

10:01:06 PM:   In Build command from Netlify app:

10:01:06 PM:   npm run build

10:01:06 PM: ​

10:01:06 PM:   Resolved config

10:01:06 PM:   build:

10:01:06 PM:     base: /opt/build/repo

10:01:06 PM:     command: npm run build

10:01:06 PM:     commandOrigin: ui

10:01:06 PM:     environment:

10:01:06 PM:       - SANITY_DEPLOY_STUDIO_TOKEN

10:01:06 PM:     publish: /opt/build/repo/web/public

10:01:06 PM:   functions:

10:01:06 PM:     '*': {}

10:01:06 PM: Caching artifacts

10:01:06 PM: Started saving node modules

10:01:06 PM: Finished saving node modules

10:01:06 PM: Started saving build plugins

10:01:06 PM: Finished saving build plugins

10:01:06 PM: Started saving pip cache

10:01:07 PM: Finished saving pip cache

10:01:07 PM: Started saving emacs cask dependencies

10:01:07 PM: Finished saving emacs cask dependencies

10:01:07 PM: Started saving maven dependencies

10:01:07 PM: Finished saving maven dependencies

10:01:07 PM: Started saving boot dependencies

10:01:07 PM: Finished saving boot dependencies

10:01:07 PM: Started saving rust rustup cache

10:01:07 PM: Finished saving rust rustup cache

10:01:07 PM: Started saving go dependencies

10:01:07 PM: Finished saving go dependencies

10:01:07 PM: Build failed due to a user error: Build script returned non-zero exit code: 2

10:01:07 PM: Creating deploy upload records

10:01:07 PM: Failing build: Failed to build site

10:01:07 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2

10:01:07 PM: Finished processing build request in 18.187527646s

Does your package.json list gatsby in dependencies?

yes.

"dependencies": {
    "@sanity/block-content-to-react": "^2.0.7",
    "@sanity/image-url": "^0.140.22",
    "date-fns": "^2.19.0",
    "gatsby": "^3.0.3",
    "gatsby-image": "^2.0.41",
    "gatsby-plugin-image": "^1.0.0",
    "gatsby-plugin-postcss": "^4.0.0",
    "gatsby-plugin-react-helmet": "^4.0.0",
    "gatsby-source-sanity": "^7.0.2",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-helmet": "^6.1.0",
    "react-syntax-highlighter": "^15.4.3"
  }
}

Well that’s a bummer. Would it be possible for you to share your repo?

sure, https://github.com/mxysaj/launchblog.git

You need all the dependencies to exist in your top-level package.json which is not the case:

Netlify only installs the dependencies listed here and not in sub-folders.

Your’e right, because when I created a new repo and installed all the dependencies it worked!
Thanks a lot.