Please help! Trying to deploy a site using Next.JS!

I’ve literally tried so many fixes. NOTHING helped.

“build.command” failed

11:08:18 PM: Build ready to start
11:08:21 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
11:08:21 PM: build-image tag: v4.10.1
11:08:21 PM: buildbot version: 37262c48b1f3cfa88c6caed707d29b19aef6a5a7
11:08:21 PM: Building without cache
11:08:21 PM: Starting to prepare the repo for build
11:08:21 PM: No cached dependencies found. Cloning fresh repo
11:08:21 PM: git clone GitHub - jayhubb4/ecommerce: Ecommerce sample
11:08:54 PM: Preparing Git Reference refs/heads/main
11:08:56 PM: Parsing package.json dependencies
11:08:57 PM: Starting build script
11:08:57 PM: Installing dependencies
11:08:57 PM: Python version set to 2.7
11:08:57 PM: Downloading and installing node v16.17.0…
11:08:58 PM: Downloading
11:08:58 PM: Computing checksum with sha256sum
11:08:58 PM: Checksums matched!
11:09:03 PM: Now using node v16.17.0 (npm v8.15.0)
11:09:03 PM: Started restoring cached build plugins
11:09:03 PM: Finished restoring cached build plugins
11:09:03 PM: Attempting ruby version 2.7.2, read from environment
11:09:04 PM: Using ruby version 2.7.2
11:09:04 PM: Using PHP version 8.0
11:09:04 PM: No npm workspaces detected
11:09:04 PM: Started restoring cached node modules
11:09:04 PM: Finished restoring cached node modules
11:09:05 PM: Installing NPM modules using NPM version 8.15.0
11:09:05 PM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
11:09:05 PM: npm WARN config location in the cache, and they are managed by
11:09:05 PM: npm WARN config
11:09:05 PM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
11:09:05 PM: npm WARN config location in the cache, and they are managed by
11:09:05 PM: npm WARN config cacache.
11:09:06 PM: added 61 packages, and audited 62 packages in 801ms
11:09:06 PM: 4 packages are looking for funding
11:09:06 PM: run npm fund for details
11:09:06 PM: found 0 vulnerabilities
11:09:06 PM: NPM modules installed
11:09:06 PM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
11:09:06 PM: npm WARN config location in the cache, and they are managed by
11:09:06 PM: npm WARN config cacache.
11:09:06 PM: Started restoring cached go cache
11:09:06 PM: Finished restoring cached go cache
11:09:06 PM: Installing Go version 1.17 (requested 1.17)
11:09:11 PM: unset GOOS;
11:09:11 PM: unset GOARCH;
11:09:11 PM: export GOROOT=‘/opt/buildhome/.gimme/versions/go1.17.linux.amd64’;
11:09:11 PM: export PATH=“/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}”;
11:09:11 PM: go version >&2;
11:09:11 PM: export GIMME_ENV=“/opt/buildhome/.gimme/env/go1.17.linux.amd64.env”
11:09:11 PM: go version go1.17 linux/amd64
11:09:11 PM: Installing missing commands
11:09:11 PM: Verify run directory
11:09:12 PM: ​
11:09:12 PM: ────────────────────────────────────────────────────────────────
11:09:12 PM: Netlify Build
11:09:12 PM: ────────────────────────────────────────────────────────────────
11:09:12 PM: ​
11:09:12 PM: ❯ Version
11:09:12 PM: @netlify/build 27.17.1
11:09:12 PM: ​
11:09:12 PM: ❯ Flags
11:09:12 PM: baseRelDir: true
11:09:12 PM: buildId: 63195ca2456750180583b03f
11:09:12 PM: deployId: 63195ca2456750180583b041
11:09:12 PM: ​
11:09:12 PM: ❯ Current directory
11:09:12 PM: /opt/build/repo
11:09:12 PM: ​
11:09:12 PM: ❯ Config file
11:09:12 PM: No config file was defined: using default values.
11:09:12 PM: ​
11:09:12 PM: ❯ Context
11:09:12 PM: production
11:09:12 PM: ​
11:09:12 PM: ────────────────────────────────────────────────────────────────
11:09:12 PM: 1. Build command from Netlify app
11:09:12 PM: ────────────────────────────────────────────────────────────────
11:09:12 PM: ​
11:09:12 PM: $ CI=‘’ npm run build
11:09:13 PM: npm WARN config tmp This setting is no longer used. npm stores temporary files in a special
11:09:13 PM: npm WARN config location in the cache, and they are managed by
11:09:13 PM: npm WARN config cacache.
11:09:13 PM: npm ERR! Missing script: “build”
11:09:13 PM: npm ERR!
11:09:13 PM: npm ERR! To see a list of scripts, run:
11:09:13 PM: npm ERR! npm run
11:09:13 PM: npm ERR! A complete log of this run can be found in:
11:09:13 PM: npm ERR! /opt/buildhome/.npm/_logs/2022-09-08T03_09_13_124Z-debug-0.log
11:09:13 PM: ​
11:09:13 PM: ────────────────────────────────────────────────────────────────
11:09:13 PM: “build.command” failed
11:09:13 PM: ────────────────────────────────────────────────────────────────
11:09:13 PM: ​
11:09:13 PM: Error message
11:09:13 PM: Command failed with exit code 1: CI=‘’ npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
11:09:13 PM: ​
11:09:13 PM: Error location
11:09:13 PM: In Build command from Netlify app:
11:09:13 PM: CI=‘’ npm run build
11:09:13 PM: ​
11:09:13 PM: Resolved config
11:09:13 PM: build:
11:09:13 PM: command: CI=‘’ npm run build
11:09:13 PM: commandOrigin: ui
11:09:13 PM: environment:
11:09:13 PM: - NEXT_PUBLIC_SANITY_TOKEN
11:09:13 PM: - NEXT_PUBLIC_STRIPE_PUBLISHEABLE_KEY
11:09:13 PM: - NEXT_PUBLIC_STRIPE_SECRET_KEY
11:09:13 PM: publish: /opt/build/repo/ecomm/.next
11:09:13 PM: publishOrigin: ui
11:09:13 PM: Caching artifacts
11:09:13 PM: Started saving node modules
11:09:15 PM: Creating deploy upload records
11:09:13 PM: Finished saving node modules
11:09:13 PM: Started saving build plugins
11:09:13 PM: Finished saving build plugins
11:09:13 PM: Started saving pip cache
11:09:15 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
11:09:13 PM: Finished saving pip cache
11:09:13 PM: Started saving emacs cask dependencies
11:09:13 PM: Finished saving emacs cask dependencies
11:09:13 PM: Started saving maven dependencies
11:09:13 PM: Finished saving maven dependencies
11:09:13 PM: Started saving boot dependencies
11:09:13 PM: Finished saving boot dependencies
11:09:13 PM: Started saving rust rustup cache
11:09:13 PM: Finished saving rust rustup cache
11:09:13 PM: Started saving go dependencies
11:09:13 PM: Finished saving go dependencies
11:09:15 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:09:15 PM: Failing build: Failed to build site
11:09:15 PM: Finished processing build request in 54.489033145s

Hello @jayhubb4 , thanks for posting.
I see you made the same post twice. Kindly make sure you post once for a particular problem for the Support Engineers to assist you better.

Now regarding your problem, you have a sub-folder called ecomm in your project root which contains your app files.
When deploying from GitHub to Netlify using the Dashboard UI, set the following below.

base folder to ecomm/
build command to next build
publish directory to .next/

You can also check the Support Guide link below for more information on Troubleshooting problems encountered during builds.

Let me know if it works.

Hi! I apologize for duplicating this post. I couldn’t see the original one so I thought that it didn’t actually post. Thank you for responding. I am unable to change the publish directory to something different from the base directory. Any suggestions? Is it because my project is in a sub folder /ecomm?

Best Regards,
Jonathan L. Hubbard

Hello @jayhubb4 , thanks for the extra feedback.

When you say you can’t change to the publish directory can you indicate what you actually mean?

You can set the publish directory in the Netlify UI dashboard. You will see the default text ecomm/ in the publish directory input field. Just append .next/ to the default text in publish directory input field. The final text will be ecomm/.next/

Screenshot (14)

Let me know the outcome. Thanks.

It seems as if I’m physically unable to from the UI. Publish directory and base directory seem to have to match.

Best Regards,
Jonathan L. Hubbard

Sorry never mind! I was just able to change the publish directory. I’m going to try to build this.

Best Regards,
Jonathan L. Hubbard

1 Like

Hi @jayhubb4 , Good to know you were able to change the publish directory.
Let me know if your deployment is successful.

Unfortunately it wasn’t. I’m not in a place where I can attach my code, so here is a photo of what I see:

Best Regards,
Jonathan L. Hubbard

Hey there, @jayhubb4 :wave:

Can you please share your netlify site name or site id with us so that we can look into this further? Thank you!

1 Like

Sure thing. The site ID is 827bfca7-95fc-4798-8a0f-52c92724d905. Thank you all so much for your help!

Best Regards,
Jonathan L. Hubbard

Hi! Were you all able to find any discrepancies?

Best Regards,
Jonathan L. Hubbard

Thanks for your patience, @jayhubb4! I have shared this with our Support Engineers. More soon!

Ok thank you! I’ve made more deployment attempts based on info I’ve received from various places so hopefully they can see those as well

Best Regards,
Jonathan L. Hubbard

I’ve figured it out! Thank you so much!

Best Regards,
Jonathan L. Hubbard

1 Like