Home
Support Forums

Gatsby build command does not work when deploy without CLEAR CACHE

Hi

I have a problem building my website.
Here is the error extracted from the logs:
6:22:33 PM: > gatsby build
6:22:33 PM: lerna ERR! npm run build stderr:
6:22:33 PM: sh: 1: gatsby: not found

When I go to the Netlify console I can CLEAR CACHE AND DEPLOY SITE manually, and it works. But of course, it is not satisfied as our continuous development doesn’t work as any external hook doesn’t.

Thx


BUILD SETTINGS

Base directory: /
Build command: npm run build
Publish directory: /web/public
Builds: Active

LOGS

6:19:48 PM: Waiting for other deploys from your team to complete
6:22:09 PM: Build ready to start
6:22:11 PM: build-image version: 09c2cdcdf242cf2f57c9ee0fcad9d298fad9ad41
6:22:11 PM: build-image tag: v3.5.0
6:22:11 PM: buildbot version: df708c2c221a3345a3fb36b8609ebca30cb2f6c5
6:22:11 PM: Fetching cached dependencies
6:22:11 PM: Starting to download cache of 100.3MB
6:22:12 PM: Finished downloading cache in 1.339410084s
6:22:12 PM: Starting to extract cache
6:22:16 PM: Finished extracting cache in 4.315188645s
6:22:16 PM: Finished fetching cache in 5.710076294s
6:22:16 PM: Starting to prepare the repo for build
6:22:17 PM: Preparing Git Reference refs/heads/production
6:22:19 PM: Different build dir detected, going to use the one specified in the Netlify configuration file: ‘’ versus ‘/’ in the Netlify UI
6:22:19 PM: Starting build script
6:22:19 PM: Installing dependencies
6:22:19 PM: Python version set to 2.7
6:22:20 PM: Started restoring cached node version
6:22:24 PM: Finished restoring cached node version
6:22:25 PM: v12.18.0 is already installed.
6:22:26 PM: Now using node v12.18.0 (npm v6.14.4)
6:22:26 PM: Started restoring cached build plugins
6:22:26 PM: Finished restoring cached build plugins
6:22:26 PM: Attempting ruby version 2.7.1, read from environment
6:22:28 PM: Using ruby version 2.7.1
6:22:29 PM: Using PHP version 5.6
6:22:29 PM: Started restoring cached node modules
6:22:29 PM: Finished restoring cached node modules
6:22:29 PM: Started restoring cached go cache
6:22:29 PM: Finished restoring cached go cache
6:22:29 PM: go version go1.14.4 linux/amd64
6:22:29 PM: go version go1.14.4 linux/amd64
6:22:29 PM: Installing missing commands
6:22:29 PM: Verify run directory
6:22:31 PM: ​
6:22:31 PM: ┌─────────────────────────────┐
6:22:31 PM: │ Netlify Build │
6:22:31 PM: └─────────────────────────────┘
6:22:31 PM: ​
6:22:31 PM: ❯ Version
6:22:31 PM: @netlify/build 5.2.1
6:22:31 PM: ​
6:22:31 PM: ❯ Flags
6:22:31 PM: deployId: 5fb17143a7fb5400083586c4
6:22:31 PM: mode: buildbot
6:22:31 PM: ​
6:22:31 PM: ❯ Current directory
6:22:31 PM: /opt/build/repo
6:22:31 PM: ​
6:22:31 PM: ❯ Config file
6:22:31 PM: No config file was defined: using default values.
6:22:31 PM: ​
6:22:31 PM: ❯ Context
6:22:31 PM: production
6:22:31 PM: ​
6:22:31 PM: ┌───────────────────────────────────┐
6:22:31 PM: │ 1. Build command from Netlify app │
6:22:31 PM: └───────────────────────────────────┘
6:22:31 PM: ​
6:22:31 PM: $ npm run build
6:22:32 PM: > sanity-gatsby-blog@1.0.17 build /opt/build/repo
6:22:32 PM: > lerna run build --parallel
6:22:32 PM: lerna notice cli v3.22.1
6:22:32 PM: lerna info ci enabled
6:22:32 PM: lerna info Executing command in 2 packages: “npm run build”
6:22:33 PM: sanity-gatsby-blog-studio: > sanity-gatsby-blog-studio@1.0.13 build /opt/build/repo/studio
6:22:33 PM: sanity-gatsby-blog-studio: > sanity build
6:22:33 PM: sanity-gatsby-blog-web: > sanity-gatsby-blog-web@1.0.5 build /opt/build/repo/web
6:22:33 PM: sanity-gatsby-blog-web: > gatsby build
6:22:33 PM: sanity-gatsby-blog-web: sh: 1: gatsby: not found
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! code ELIFECYCLE
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! syscall spawn
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! file sh
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! errno ENOENT
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! sanity-gatsby-blog-web@1.0.5 build: gatsby build
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! spawn ENOENT
6:22:33 PM: sanity-gatsby-blog-web: npm ERR!
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! Failed at the sanity-gatsby-blog-web@1.0.5 build script.
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
6:22:33 PM: sanity-gatsby-blog-web: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! A complete log of this run can be found in:
6:22:33 PM: sanity-gatsby-blog-web: npm ERR! /opt/buildhome/.npm/_logs/2020-11-15T18_22_33_182Z-debug.log
6:22:33 PM: lerna ERR! npm run build exited 1 in ‘sanity-gatsby-blog-web’
6:22:33 PM: lerna ERR! npm run build stdout:
6:22:33 PM: > sanity-gatsby-blog-web@1.0.5 build /opt/build/repo/web
6:22:33 PM: > gatsby build
6:22:33 PM: lerna ERR! npm run build stderr:
6:22:33 PM: sh: 1: gatsby: not found
6:22:33 PM: npm ERR! code ELIFECYCLE
6:22:33 PM: npm ERR! syscall spawn
6:22:33 PM: npm ERR! file sh
6:22:33 PM: npm ERR! errno ENOENT
6:22:33 PM: npm ERR! sanity-gatsby-blog-web@1.0.5 build: gatsby build
6:22:33 PM: npm ERR! spawn ENOENT
6:22:33 PM: npm ERR!
6:22:33 PM: npm ERR! Failed at the sanity-gatsby-blog-web@1.0.5 build script.
6:22:33 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
6:22:33 PM: npm WARN Local package.json exists, but node_modules missing, did you mean to install?
6:22:33 PM: npm ERR! A complete log of this run can be found in:
6:22:33 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-11-15T18_22_33_182Z-debug.log
6:22:33 PM: lerna ERR! npm run build exited 1 in ‘sanity-gatsby-blog-web’
6:22:33 PM: lerna WARN complete Waiting for 1 child process to exit. CTRL-C to exit immediately.
6:22:33 PM: npm ERR! code ELIFECYCLE
6:22:33 PM: npm ERR! errno 1
6:22:33 PM: npm ERR! sanity-gatsby-blog@1.0.17 build: lerna run build --parallel
6:22:33 PM: npm ERR! Exit status 1
6:22:33 PM: npm ERR!
6:22:33 PM: npm ERR! Failed at the sanity-gatsby-blog@1.0.17 build script.
6:22:33 PM: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
6:22:33 PM: npm ERR! A complete log of this run can be found in:
6:22:33 PM: npm ERR! /opt/buildhome/.npm/_logs/2020-11-15T18_22_33_215Z-debug.log
6:22:33 PM: ​
6:22:33 PM: ┌─────────────────────────────┐
6:22:33 PM: │ “build.command” failed │
6:22:33 PM: └─────────────────────────────┘
6:22:33 PM: ​
6:22:33 PM: Error message
6:22:33 PM: Command failed with exit code 1: npm run build
6:22:33 PM: ​
6:22:33 PM: Error location
6:22:33 PM: In Build command from Netlify app:
6:22:33 PM: npm run build
6:22:33 PM: ​
6:22:33 PM: Resolved config
6:22:33 PM: build:
6:22:33 PM: base: /opt/build/repo
6:22:33 PM: command: npm run build
6:22:33 PM: commandOrigin: ui
6:22:33 PM: environment:
6:22:33 PM: - SANITY_DEPLOY_STUDIO_TOKEN
6:22:33 PM: publish: /opt/build/repo/web/public
6:22:33 PM: Caching artifacts
6:22:33 PM: Started saving node modules
6:22:33 PM: Finished saving node modules
6:22:33 PM: Started saving build plugins
6:22:33 PM: Finished saving build plugins
6:22:33 PM: Started saving pip cache
6:22:33 PM: Finished saving pip cache
6:22:33 PM: Started saving emacs cask dependencies
6:22:33 PM: Finished saving emacs cask dependencies
6:22:33 PM: Started saving maven dependencies
6:22:33 PM: Finished saving maven dependencies
6:22:33 PM: Started saving boot dependencies
6:22:33 PM: Finished saving boot dependencies
6:22:33 PM: Started saving go dependencies
6:22:33 PM: Finished saving go dependencies
6:22:33 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:22:33 PM: Failing build: Failed to build site
6:22:33 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
6:22:33 PM: Finished processing build request in 22.679273581s

May we have a look at your repo?

Hey… What do you want to see from my repo? I can’t open the access but I can extract some elements…

Here’s one support thread that you might want to check out first: [Support Guide] My site deploy fails unless Netlify's build cache is cleared

Well, I was hoping for the entire thing as I’m seeing this problem for the first time. It usually doesn’t happen that one has to clear cache and deploy, so, there’s something unusual and I can’t say what it is. If I could, I’d have asked you to share only a limited part.

However, if you can’t open public access, you can do one of the two things:

  1. Either create a minimal reproduction of the problem, that is, a repo that can produce this error with minimum content, that’s similar to your use case.

  2. Or, just share the current repo with sensitive information removed and any other parts that you might not want to share.