Gatsby 4 Deploy Error

Not sure why it’s asking me to run gatsby develop or that it might be necessary to add env variables. I only added “npm install -g npm@8.5.5” recently to see if that would help. I also set NPM_FLAGS to --legacy-peer-deps also

3:00:43 AM: info Done building in 127.324099473 sec
3:00:45 AM: err could not establish a connection with the dev server
3:00:45 AM: attempted connection to http://localhost:8000/___graphql
3:00:45 AM: make sure you"ve run gatsby develop and set the
following env variables (if necessary)
3:00:45 AM: - HOST (default: localhost)
3:00:45 AM: - PORT (default: 8000)
3:00:45 AM: - LOG_LEVEL (default: error)
3:00:45 AM: - GRAPHQL_PATH (default: /___graphql)
3:00:45 AM: ​
3:00:45 AM: “build.command” failed
3:00:45 AM: ────────────────────────────────────────────────────────────────
3:00:45 AM: ​
3:00:45 AM: Error message
3:00:45 AM: Command failed with exit code 1: npm install -g npm@8.5.5 && npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
3:00:45 AM: ​
3:00:45 AM: Error location
3:00:45 AM: In Build command from Netlify app:
3:00:45 AM: npm install -g npm@8.5.5 && npm run build
3:00:45 AM: ​
3:00:45 AM: Resolved config
3:00:45 AM: build:
3:00:45 AM: base: /opt/build/repo/client
3:00:45 AM: command: npm install -g npm@8.5.5 && npm run build
3:00:45 AM: commandOrigin: ui
3:00:45 AM: environment:
3:00:45 AM: - NPM_FLAGS
3:00:45 AM: publish: /opt/build/repo/client/public
3:00:45 AM: publishOrigin: ui
3:00:45 AM: plugins:
3:00:45 AM: - inputs: {}
3:00:45 AM: origin: config
3:00:45 AM: package: “@netlify/plugin-gatsby”
3:00:45 AM: Caching artifacts
3:00:45 AM: Started saving node modules
3:00:45 AM: Finished saving node modules
3:00:45 AM: Started saving build plugins
3:00:45 AM: Finished saving build plugins
3:00:45 AM: Started saving corepack cache
3:00:45 AM: Finished saving corepack cache
3:00:45 AM: Started saving yarn cache
3:00:49 AM: Finished saving yarn cache
3:00:49 AM: Started saving pip cache
3:00:49 AM: Finished saving pip cache
3:00:49 AM: Started saving emacs cask dependencies
3:00:49 AM: Finished saving emacs cask dependencies
3:00:49 AM: Started saving maven dependencies
3:00:49 AM: Finished saving maven dependencies
3:00:49 AM: Started saving boot dependencies
3:00:49 AM: Finished saving boot dependencies
3:00:49 AM: Started saving rust rustup cache
3:00:49 AM: Finished saving rust rustup cache
3:00:49 AM: Started saving go dependencies
3:00:49 AM: Finished saving go dependencies
3:00:50 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:00:50 AM: Failing build: Failed to build site
3:00:50 AM: Finished processing build request in 3m13.737s
3:00:50 AM: Failed during stage “building site”: Build script returned non-zero exit code: 2

Hi @jakebir,

Thanks for reaching out and welcome to Netlify’s Support Forums!

Could you clarify that the issue only started after adding npm install -g npm@8.5.5”?

Also could you provide us with the sitename? Such as sitenate.netlify.app.

The subdomain is tspdx.netlify.app

I apologize for the confusion, I was attempting npm install -g npm@8.5.5 to see if that would help. The problem was occurring even before applying this. I also noticed it’s not necessary because I am specifying node v16.15.0 which I believe uses npm v8.5.5

here is another deploy attempt without “npm install -g npm@8.5.5”

9:22:06 AM: err could not establish a connection with the dev server
9:22:06 AM: attempted connection to http://localhost:8000/___graphql
9:22:06 AM: make sure you"ve run gatsby develop and set the
following env variables (if necessary)
9:22:06 AM: - HOST (default: localhost)
9:22:06 AM: - PORT (default: 8000)
9:22:06 AM: - LOG_LEVEL (default: error)
9:22:06 AM: - GRAPHQL_PATH (default: /___graphql)
9:22:06 AM: ​
9:22:06 AM: “build.command” failed
9:22:06 AM: ────────────────────────────────────────────────────────────────
9:22:06 AM: ​
9:22:06 AM: Error message
9:22:06 AM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
9:22:06 AM: ​
9:22:06 AM: Error location
9:22:06 AM: In Build command from Netlify app:
9:22:06 AM: npm run build
9:22:06 AM: ​
9:22:06 AM: Resolved config
9:22:06 AM: build:
9:22:06 AM: base: /opt/build/repo/client
9:22:06 AM: command: npm run build
9:22:06 AM: commandOrigin: ui
9:22:06 AM: environment:
9:22:06 AM: - NPM_FLAGS
9:22:06 AM: publish: /opt/build/repo/client/public
9:22:06 AM: publishOrigin: ui
9:22:06 AM: plugins:
9:22:06 AM: - inputs: {}
9:22:06 AM: origin: config
9:22:06 AM: package: “@netlify/plugin-gatsby”
9:22:13 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:22:13 AM: Failing build: Failed to build site
9:22:13 AM: Finished processing build request in 3m3.251s
9:22:13 AM: Failed during stage “building site”: Build script returned non-zero exit code: 2

Whatever you’re doing along these lines is the issue:

Why would your app try to connect to localhost? Maybe you’ve set some incorrect variables or not set anything at all so it’s falling back to some default values.

I appreciate your input. Yes, I’m aware of the error, and that’s precisely why I posted this. I’m unsure why it’s connecting to localhost when I’m using ‘build’ as a command. Since you are Netlify taking over for Gatsby, I was wondering if you might have some insights into this. :slight_smile:

We do not have any insights about your project or can see what’s happening in there during the build process. Feel free to try to create a minimal reproduction and we can take a look.