Build.Command Failed

First time using Netlify, I created an app with npx create-next-app@latest and uploaded to DevOps, AFAIK everything is done correctly.

3:08:55 PM: Build ready to start
3:08:58 PM: build-image version: d7b3dbfb0846505993c9a131894d1858074c90b4 (focal)
3:08:58 PM: build-image tag: v4.10.1
3:08:58 PM: buildbot version: 37262c48b1f3cfa88c6caed707d29b19aef6a5a7
3:08:58 PM: Fetching cached dependencies
3:08:58 PM: Failed to fetch cache, continuing with build
3:08:58 PM: Starting to prepare the repo for build
3:08:58 PM: No cached dependencies found. Cloning fresh repo
3:08:58 PM: git clone https://dev.azure.com/Wizardboots03/Sporefare/_git/Sporefare
3:09:00 PM: Preparing Git Reference refs/heads/main
3:09:01 PM: Parsing package.json dependencies
3:09:01 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: β€˜out’ versus β€˜β€™ in the Netlify UI
3:09:01 PM: Different build command detected, going to use the one specified in the Netlify configuration file: β€˜yarn build’ versus β€˜β€™ in the Netlify UI
3:09:01 PM: Starting build script
3:09:01 PM: Installing dependencies
3:09:01 PM: Python version set to 2.7
3:09:02 PM: Downloading and installing node v16.17.0…
3:09:02 PM: Downloading https://nodejs.org/dist/v16.17.0/node-v16.17.0-linux-x64.tar.xz…
3:09:04 PM: Computing checksum with sha256sum
3:09:04 PM: Checksums matched!
3:09:06 PM: Now using node v16.17.0 (npm v8.15.0)
3:09:06 PM: Started restoring cached build plugins
3:09:06 PM: Finished restoring cached build plugins
3:09:06 PM: Attempting ruby version 2.7.2, read from environment
3:09:07 PM: Using ruby version 2.7.2
3:09:07 PM: Using PHP version 8.0
3:09:07 PM: Started restoring cached go cache
3:09:07 PM: Finished restoring cached go cache
3:09:07 PM: Installing Go version 1.17 (requested 1.17)
3:09:12 PM: unset GOOS;
3:09:12 PM: unset GOARCH;
3:09:12 PM: export GOROOT=β€˜/opt/buildhome/.gimme/versions/go1.17.linux.amd64’;
3:09:12 PM: export PATH=β€œ/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}”;
3:09:12 PM: go version >&2;
3:09:12 PM: export GIMME_ENV=β€œ/opt/buildhome/.gimme/env/go1.17.linux.amd64.env”
3:09:12 PM: go version go1.17 linux/amd64
3:09:12 PM: Installing missing commands
3:09:12 PM: Verify run directory
3:09:13 PM: ​
3:09:13 PM: ────────────────────────────────────────────────────────────────
3:09:13 PM: Netlify Build
3:09:13 PM: ────────────────────────────────────────────────────────────────
3:09:13 PM: ​
3:09:13 PM: ❯ Version
3:09:13 PM: @netlify/build 27.17.1
3:09:13 PM: ​
3:09:13 PM: ❯ Flags
3:09:13 PM: baseRelDir: true
3:09:13 PM: buildId: 6318a5f70cab8f0aeff95212
3:09:13 PM: deployId: 6318a5f70cab8f0aeff95214
3:09:13 PM: ​
3:09:13 PM: ❯ Current directory
3:09:13 PM: /opt/build/repo
3:09:13 PM: ​
3:09:13 PM: ❯ Config file
3:09:13 PM: /opt/build/repo/netlify.toml
3:09:13 PM: ​
3:09:13 PM: ❯ Context
3:09:13 PM: production
3:09:13 PM: ​
3:09:13 PM: ❯ Installing plugins
3:09:13 PM: - @netlify/plugin-nextjs@4.21.1
3:09:13 PM: - netlify-plugin-cache-nextjs@1.4.0
3:09:25 PM: ​
3:09:25 PM: ❯ Loading plugins
3:09:25 PM: - @netlify/plugin-nextjs@4.21.1 from netlify.toml
3:09:25 PM: - netlify-plugin-cache-nextjs@1.4.0 from netlify.toml
3:09:26 PM: ​
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: 1. @netlify/plugin-nextjs (onPreBuild event)
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: ​
3:09:26 PM: No Next.js cache to restore.
3:09:26 PM: Netlify configuration property β€œbuild.environment.NEXT_PRIVATE_TARGET” value changed.
3:09:26 PM: ​
3:09:26 PM: (@netlify/plugin-nextjs onPreBuild completed in 17ms)
3:09:26 PM: ​
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: 2. netlify-plugin-cache-nextjs (onPreBuild event)
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: ​
3:09:26 PM: No cache found for the .next folder at the location .next/cache
3:09:26 PM: ​
3:09:26 PM: (netlify-plugin-cache-nextjs onPreBuild completed in 6ms)
3:09:26 PM: ​
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: 3. build.command from netlify.toml
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: ​
3:09:26 PM: $ yarn build
3:09:26 PM: yarn run v1.22.10
3:09:26 PM: error Couldn’t find a package.json file in "/opt/build/repo"info Visit yarn run | Yarn for documentation about this command.
3:09:26 PM: ​
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: β€œbuild.command” failed
3:09:26 PM: ────────────────────────────────────────────────────────────────
3:09:26 PM: ​
3:09:26 PM: Error message
3:09:26 PM: Command failed with exit code 1: yarn build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
3:09:26 PM: ​
3:09:26 PM: Error location
3:09:26 PM: In build.command from netlify.toml:
3:09:26 PM: yarn build
3:09:26 PM: ​
3:09:26 PM: Resolved config
3:09:26 PM: build:
3:09:26 PM: command: yarn build
3:09:26 PM: commandOrigin: config
3:09:26 PM: environment:
3:09:26 PM: - NEXT_PRIVATE_TARGET
3:09:26 PM: publish: /opt/build/repo/out
3:09:26 PM: publishOrigin: config
3:09:26 PM: plugins:
3:09:26 PM: - inputs: {}
3:09:26 PM: origin: config
3:09:26 PM: package: β€˜@netlify/plugin-nextjs’
3:09:26 PM: - inputs: {}
3:09:26 PM: origin: config
3:09:26 PM: package: netlify-plugin-cache-nextjs
3:09:27 PM: Caching artifacts
3:09:28 PM: Creating deploy upload records
3:09:27 PM: Started saving build plugins
3:09:27 PM: Finished saving build plugins
3:09:27 PM: Started saving pip cache
3:09:27 PM: Finished saving pip cache
3:09:28 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)
3:09:27 PM: Started saving emacs cask dependencies
3:09:27 PM: Finished saving emacs cask dependencies
3:09:27 PM: Started saving maven dependencies
3:09:27 PM: Finished saving maven dependencies
3:09:27 PM: Started saving boot dependencies
3:09:27 PM: Finished saving boot dependencies
3:09:27 PM: Started saving rust rustup cache
3:09:27 PM: Finished saving rust rustup cache
3:09:27 PM: Started saving go dependencies
3:09:27 PM: Finished saving go dependencies
3:09:28 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:09:28 PM: Failing build: Failed to build site
3:09:28 PM: Finished processing build request in 30.741507101s

@KirkJL , sorry that your build is failing.
I see that you are trying to deploy from Azure DevOps. It seems there is another sub-folder called sporefare in the root folder. Therefore in your netlify.toml file, you need to set the base folder to sporefare.

base = "sporefare/" just means the directory to change to before starting a build and also where Netlify will look for package.json/.nvmrc/etc.

Your netlify.toml file should now look like the code below.

[build]
  base = "sporefare/"
  command = "yarn build"
  publish = "out/"

[[plugins]]
  package = "@netlify/plugin-nextjs"

[[plugins]]
  package = "netlify-plugin-cache-nextjs"

Let me know if the changes helps. Thanks.

Thanks for the help, managed to get past that and now get a config error

5:04:12 PM: $ yarn build
5:04:12 PM: yarn run v1.22.10
5:04:12 PM: $ next build
5:04:12 PM: info - SWC minify release candidate enabled. swc-minify-enabled | Next.js
5:04:12 PM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
5:04:12 PM: info - Linting and checking validity of types…
5:04:14 PM: info - Creating an optimized production build…
5:04:16 PM: info - Compiled successfully
5:04:16 PM: info - Collecting page data…
5:04:19 PM: info - Generating static pages (0/3)
5:04:19 PM: info - Generating static pages (3/3)
5:04:20 PM: info - Finalizing page optimization…
5:04:20 PM: Route (pages) Size First Load JS
5:04:20 PM: β”Œ β—‹ / 5.42 kB 83.3 kB
5:04:20 PM: β”œ β”” css/ae0e3e027412e072.css 707 B
5:04:20 PM: β”œ /_app 0 B 77.9 kB
5:04:20 PM: β”œ β—‹ /404 186 B 78.1 kB
5:04:20 PM: β”” Ξ» /api/hello 0 B 77.9 kB
5:04:20 PM: + First Load JS shared by all 78.1 kB
5:04:20 PM: β”œ chunks/framework-db825bd0b4ae01ef.js 45.7 kB
5:04:20 PM: β”œ chunks/main-3123a443c688934f.js 30.9 kB
5:04:20 PM: β”œ chunks/pages/_app-0e6b46beaaa55ac1.js 498 B
5:04:20 PM: β”œ chunks/webpack-7ee66019f7f6d30f.js 755 B
5:04:20 PM: β”” css/ab44ce7add5c3d11.css 247 B
5:04:20 PM: Ξ» (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)
5:04:20 PM: β—‹ (Static) automatically rendered as static HTML (uses no initial props)
5:04:20 PM: Done in 7.89s.
5:04:20 PM: ​
5:04:20 PM: (build.command completed in 8s)
5:04:20 PM: ​
5:04:20 PM: ────────────────────────────────────────────────────────────────
5:04:20 PM: 2. Deploy site
5:04:20 PM: ────────────────────────────────────────────────────────────────
5:04:20 PM: ​
5:04:20 PM: ​
5:04:20 PM: ────────────────────────────────────────────────────────────────
5:04:20 PM: Configuration error
5:04:20 PM: ────────────────────────────────────────────────────────────────
5:04:20 PM: ​
5:04:20 PM: Error message
5:04:20 PM: Deploy did not succeed: Deploy directory β€˜sporefare/out’ does not exist
5:04:20 PM: ​
5:04:20 PM: Resolved config
5:04:20 PM: build:
5:04:20 PM: base: /opt/build/repo/sporefare
5:04:20 PM: command: yarn build
5:04:20 PM: commandOrigin: config
5:04:20 PM: publish: /opt/build/repo/sporefare/out
5:04:20 PM: publishOrigin: config
5:04:20 PM: Caching artifacts
5:04:20 PM: Started saving node modules
5:04:20 PM: Finished saving node modules
5:04:20 PM: Started saving build plugins
5:04:20 PM: Finished saving build plugins
5:04:20 PM: Started saving yarn cache
5:04:23 PM: Finished saving yarn cache
5:04:23 PM: Started saving pip cache
5:04:23 PM: Finished saving pip cache
5:04:23 PM: Started saving emacs cask dependencies
5:04:23 PM: Finished saving emacs cask dependencies
5:04:23 PM: Started saving maven dependencies
5:04:23 PM: Finished saving maven dependencies
5:04:23 PM: Started saving boot dependencies
5:04:23 PM: Finished saving boot dependencies
5:04:23 PM: Started saving rust rustup cache
5:04:23 PM: Finished saving rust rustup cache
5:04:23 PM: Started saving go dependencies
5:04:23 PM: Finished saving go dependencies
5:04:24 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:04:24 PM: Creating deploy upload records
5:04:24 PM: Failing build: Failed to build site
5:04:24 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)
5:04:24 PM: Finished processing build request in 42.425742411s

Thanks for your help, I kept getting a new user can only quote 2 people message so had to post it separate to this response, I now get a config error

Hi @KirkJL , Thanks for the extra feedback.

The cause of the error is that there is no next export in the build command inside your netlify.toml file . Since next export doesn’t get called, the out folder will not exist.

Your netlify.toml file should now look like the code below.

[build]
  base = "sporefare/"
  command = "next build && next export"
  publish = "out/"

[[plugins]]
  package = "@netlify/plugin-nextjs"

[[plugins]]
  package = "netlify-plugin-cache-nextjs"

Also note the following below.
The typical build settings for Next.js apps are as follows. They differ depending on how your site is generated.

  • For apps that use server-side rendering and Next.js Runtime:
    • Build command: next build
    • Publish directory: .next
  • For apps that use static HTML export:
    • Build command: next build && next export
    • Publish directory: out

For more information, you can also visit the link below for Next.js build settings at Framework integrations | Netlify Docs

Let me know if it works. Thanks.

YOU LEGEND! Thanks so much, changed build and publish to match server-side rendering and it worked. Thanks so much!

1 Like

@KirkJL , I’m glad I was able to help. If you are satisfied with the suggested solution, kindly mark it as solved in order to help others who might experience a similar problem in the future.
Thanks.