0

I'm currently trying to see my site on a staging environment, so I'm pushing from a staging branch. Not master.

It builds completely find locally. When pushing to Netlify, it fails.

The error I'm getting below:

3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM:   1. Build command from Netlify app                             
3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM: ​
3:31:59 PM: $ gatsby build
3:31:59 PM: bash: gatsby: command not found
3:31:59 PM: ​
3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM:   "build.command" failed                                        
3:31:59 PM: ────────────────────────────────────────────────────────────────
3:31:59 PM: ​
3:31:59 PM:   Error message
3:31:59 PM:   Command failed with exit code 127: gatsby build
3:31:59 PM: ​
3:31:59 PM:   Error location
3:31:59 PM:   In Build command from Netlify app:
3:31:59 PM:   gatsby build
3:31:59 PM: ​
3:31:59 PM:   Resolved config
3:31:59 PM:   build:
3:31:59 PM:     command: gatsby build
3:31:59 PM:     commandOrigin: ui
3:31:59 PM:     publish: /opt/build/repo/dist
3:31:59 PM: Caching artifacts
3:31:59 PM: Started saving node modules
3:31:59 PM: Finished saving node modules
3:31:59 PM: Started saving build plugins
3:31:59 PM: Finished saving build plugins
3:31:59 PM: Started saving yarn cache
3:31:59 PM: Finished saving yarn cache
3:31:59 PM: Started saving pip cache
3:31:59 PM: Finished saving pip cache
3:31:59 PM: Started saving emacs cask dependencies
3:31:59 PM: Finished saving emacs cask dependencies
3:31:59 PM: Started saving maven dependencies
3:31:59 PM: Finished saving maven dependencies
3:31:59 PM: Started saving boot dependencies
3:31:59 PM: Finished saving boot dependencies
3:31:59 PM: Started saving go dependencies
3:32:01 PM: Finished saving go dependencies
3:32:04 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:32:04 PM: Failing build: Failed to build site
3:32:04 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:32:04 PM: Finished processing build request in 1m17.166375156s

1 Answer 1

2

The error you're getting is that the gatsby CLI is not available.

bash: gatsby: command not found

  1. Check that you have gatsby in your dependencies in package.json. Note that it cannot be in your devDependencies instead.
  2. Above the error message shown, you should see Netlify pick up either Yarn or NPM and install dependencies as appropriate. If it doesn't, you may have forgotten to include package-lock.json or yarn.lock in your repo (e.g. it might be in .gitignore).
  3. To avoid issues like this in the future, add a "build" script to your package.json and switch the build command on Netlify to use it (e.g. yarn build or npm run build). This will ensure you're using the executable included in node_modules instead of a globally available tool.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.