Npm build works fine but build failed in Netlify Build after commit

netlify site: cookbookforeveryone.netlify.app, studiocookbookforeveryone.netlify.app (sanity studio)

the build went okay for first commit. After enabling some plugins for sanity (seo, dark theme etc) and gatsby (google tag etc), can build it successfully on local and work fine locally but failed once committed these changes.

Tried the following:

  • remove package-lock.json and npm install
  • Looked thru all the issues but couldn’t find something similar particularly on the missing sanity plugins as mentioned in the log.

Here’s the log:


5:27:41 PM: Build ready to start
5:27:43 PM: build-image version: b0258b965567defc4a2d7e2f2dec2e00c8f73ad6
5:27:43 PM: build-image tag: v3.4.1
5:27:43 PM: buildbot version: 0a44c930054be748eff0c581d346282fece89cc0
5:27:43 PM: Fetching cached dependencies
5:27:44 PM: Starting to download cache of 85.4MB
5:27:44 PM: Finished downloading cache in 652.988321ms
5:27:44 PM: Starting to extract cache
5:27:48 PM: Finished extracting cache in 3.86295019s
5:27:48 PM: Finished fetching cache in 4.566346029s
5:27:48 PM: Starting to prepare the repo for build
5:27:49 PM: Preparing Git Reference refs/heads/production
5:27:51 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: β€˜β€™ versus β€˜/’ in the Netlify UI
5:27:51 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: β€˜studio/dist’ versus β€˜/studio/dist’ in the Netlify UI
5:27:51 PM: Starting build script
5:27:51 PM: Installing dependencies
5:27:51 PM: Python version set to 2.7
5:27:52 PM: Started restoring cached node version
5:27:55 PM: Finished restoring cached node version
5:27:55 PM: v12.18.0 is already installed.
5:27:56 PM: Now using node v12.18.0 (npm v6.14.4)
5:27:56 PM: Started restoring cached build plugins
5:27:56 PM: Finished restoring cached build plugins
5:27:56 PM: Attempting ruby version 2.7.1, read from environment
5:27:58 PM: Using ruby version 2.7.1
5:27:58 PM: Using PHP version 5.6
5:27:58 PM: 5.2 is already installed.
5:27:58 PM: Using Swift version 5.2
5:27:58 PM: Started restoring cached node modules
5:27:58 PM: Finished restoring cached node modules
5:27:59 PM: Started restoring cached go cache
5:27:59 PM: Finished restoring cached go cache
5:27:59 PM: go version go1.14.4 linux/amd64
5:27:59 PM: go version go1.14.4 linux/amd64
5:27:59 PM: Installing missing commands
5:27:59 PM: Verify run directory
5:28:00 PM: ​
5:28:00 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
5:28:00 PM: β”‚ Netlify Build β”‚
5:28:00 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
5:28:00 PM: ​
5:28:00 PM: ❯ Version
5:28:00 PM: @netlify/build 5.0.2
5:28:00 PM: ​
5:28:00 PM: ❯ Flags
5:28:00 PM: deployId: 5f94c67d0e058ddb218b2485
5:28:00 PM: mode: buildbot
5:28:00 PM: ​
5:28:00 PM: ❯ Current directory
5:28:00 PM: /opt/build/repo
5:28:00 PM: ​
5:28:00 PM: ❯ Config file
5:28:00 PM: No config file was defined: using default values.
5:28:00 PM: ​
5:28:00 PM: ❯ Context
5:28:00 PM: production
5:28:00 PM: ​
5:28:00 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
5:28:00 PM: β”‚ 1. Build command from Netlify app β”‚
5:28:00 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
5:28:00 PM: ​
5:28:00 PM: $ npm run build-studio && cp studio/netlify.toml studio/dist
5:28:01 PM: > sanity-gatsby-blog@1.0.17 build-studio /opt/build/repo
5:28:01 PM: > lerna bootstrap && cd studio && npm run build
5:28:01 PM: lerna notice cli v3.22.0
5:28:01 PM: lerna info ci enabled
5:28:02 PM: lerna info Bootstrapping 2 packages
5:28:02 PM: lerna info Installing external dependencies
5:28:03 PM: lerna ERR! npm ci exited 1 in β€˜sanity-gatsby-blog-studio’
5:28:03 PM: lerna ERR! npm ci stderr:
5:28:03 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.
5:28:03 PM: npm ERR!
5:28:03 PM: npm ERR!
5:28:03 PM: npm ERR! Missing: sanity-plugin-content-model-graph@^1.1.1
5:28:03 PM: npm ERR! Missing: sanity-plugin-dark-theme-blue@^1.0.1
5:28:03 PM: npm ERR! Missing: sanity-plugin-markdown@^1.0.1
5:28:03 PM: npm ERR! Missing: sanity-plugin-media@^0.4.0
5:28:03 PM: npm ERR! Missing: sanity-plugin-seo-tools@^1.0.6
5:28:03 PM: npm ERR!
5:28:03 PM: npm ERR! A complete log of this run can be found in:
5:28:03 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-10-25T00_28_02_992Z-debug.log
5:28:03 PM: lerna ERR! npm ci exited 1 in β€˜sanity-gatsby-blog-studio’
5:28:03 PM: lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
5:28:03 PM: npm ERR! code ELIFECYCLE
5:28:03 PM: npm ERR! errno 1
5:28:03 PM: npm ERR! sanity-gatsby-blog@1.0.17 build-studio: lerna bootstrap && cd studio && npm run build
5:28:03 PM: npm ERR! Exit status 1
5:28:03 PM: npm ERR!
5:28:03 PM: npm ERR! Failed at the sanity-gatsby-blog@1.0.17 build-studio script.
5:28:03 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
5:28:03 PM: npm ERR! A complete log of this run can be found in:
5:28:03 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-10-25T00_28_03_034Z-debug.log
5:28:03 PM: ​
5:28:03 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
5:28:03 PM: β”‚ β€œbuild.command” failed β”‚
5:28:03 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
5:28:03 PM: ​
5:28:03 PM: Error message
5:28:03 PM: Command failed with exit code 1: npm run build-studio && cp studio/netlify.toml studio/dist
5:28:03 PM: ​
5:28:03 PM: Error location
5:28:03 PM: In Build command from Netlify app:
5:28:03 PM: npm run build-studio && cp studio/netlify.toml studio/dist
5:28:03 PM: ​
5:28:03 PM: Resolved config
5:28:03 PM: build:
5:28:03 PM: base: /opt/build/repo
5:28:03 PM: command: npm run build-studio && cp studio/netlify.toml studio/dist
5:28:03 PM: commandOrigin: ui
5:28:03 PM: environment:
5:28:03 PM: - INCOMING_HOOK_BODY
5:28:03 PM: - INCOMING_HOOK_TITLE
5:28:03 PM: - INCOMING_HOOK_URL
5:28:03 PM: publish: /opt/build/repo/studio/dist
5:28:03 PM: Caching artifacts
5:28:03 PM: Started saving node modules
5:28:03 PM: Finished saving node modules
5:28:03 PM: Started saving build plugins
5:28:03 PM: Finished saving build plugins
5:28:03 PM: Started saving pip cache
5:28:03 PM: Finished saving pip cache
5:28:03 PM: Started saving emacs cask dependencies
5:28:03 PM: Finished saving emacs cask dependencies
5:28:03 PM: Started saving maven dependencies
5:28:03 PM: Finished saving maven dependencies
5:28:03 PM: Started saving boot dependencies
5:28:03 PM: Finished saving boot dependencies
5:28:03 PM: Started saving go dependencies
5:28:03 PM: Finished saving go dependencies
5:28:03 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:28:03 PM: Failing build: Failed to build site
5:28:03 PM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2
5:28:03 PM: Finished processing build request in 19.893312204s

Did you try deleting your package-lock.json and publishing the changes?

On a side note, it’s usually recommended to add package-lock.json to .gitignore as well.

After deleting the package-lock.json file and publish the changes, then physically check github to make sure all three package-lock.json files (root,web, studio) are removed… i got the following error:

12:02:36 PM: $ npm run build-studio && cp studio/netlify.toml studio/dist

12:02:36 PM: > sanity-gatsby-blog@1.0.17 build-studio /opt/build/repo

12:02:36 PM: > lerna bootstrap && cd studio && npm run build

12:02:37 PM: lerna notice cli v3.22.0

12:02:37 PM: lerna info ci enabled

12:02:37 PM: lerna info Bootstrapping 2 packages

12:02:37 PM: lerna info Installing external dependencies

12:02:38 PM: lerna ERR! npm ci exited 1 in β€˜sanity-gatsby-blog-studio’

12:02:38 PM: lerna ERR! npm ci stderr:

12:02:38 PM: npm ERR! cipm can only install packages with an existing package-lock.json or npm-shrinkwrap.json with lockfileVersion >= 1. Run an install with npm@5 or later to generate it, then try again.

12:02:38 PM: npm ERR! A complete log of this run can be found in:

12:02:38 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-10-25T19_02_38_836Z-debug.log

12:02:38 PM: lerna ERR! npm ci exited 1 in β€˜sanity-gatsby-blog-studio’

12:02:38 PM: lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.

12:02:38 PM: npm ERR! code ELIFECYCLE

12:02:38 PM: npm ERR! errno 1

12:02:38 PM: npm ERR! sanity-gatsby-blog@1.0.17 build-studio: lerna bootstrap && cd studio && npm run build

12:02:38 PM: npm ERR! Exit status 1

12:02:38 PM: npm ERR!

12:02:38 PM: npm ERR! Failed at the sanity-gatsby-blog@1.0.17 build-studio script.

12:02:38 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

12:02:38 PM: npm ERR! A complete log of this run can be found in:

12:02:38 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-10-25T19_02_38_891Z-debug.log

12:02:38 PM: ​

12:02:38 PM: β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”

12:02:38 PM: β”‚ β€œbuild.command” failed β”‚

12:02:38 PM: β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

I then did npm install for all the three files and published again (package-lock.json files committed to github). This works this time.

The problem: I checked github history, somehow there was at least one version of package-lock.json was outdated and didn’t get updated properly in the past. Now I explicitly removed all three files and then added them back. It works.

1 Like