"build.command" failed next.js on netlify

PLEASE help me with below error

2:26:59 AM: build-image version: 1ca34a93198b041e44214013884c57d146a23fed (focal)
2:26:59 AM: build-image tag: v4.16.4
2:26:59 AM: buildbot version: 2577a19e1559072eeb7a6727cec389b63b90401c
2:26:59 AM: Building without cache
2:26:59 AM: Starting to prepare the repo for build
2:26:59 AM: No cached dependencies found. Cloning fresh repo
2:26:59 AM: git clone --filter=blob:none --no-checkout GitHub - Sunilsinh1994/NEXT2
2:26:59 AM: Preparing Git Reference refs/heads/main
2:26:59 AM: Parsing package.json dependencies
2:27:01 AM: Starting build script
2:27:01 AM: Installing dependencies
2:27:01 AM: Python version set to 2.7
2:27:01 AM: v16.19.0 is already installed.
2:27:01 AM: Now using node v16.19.0 (npm v8.19.3)
2:27:02 AM: Enabling Node.js Corepack
2:27:02 AM: Started restoring cached build plugins
2:27:02 AM: Finished restoring cached build plugins
2:27:02 AM: Attempting Ruby version 2.7.2, read from environment
2:27:02 AM: Using Ruby version 2.7.2
2:27:02 AM: Using PHP version 8.0
2:27:02 AM: Started restoring cached corepack dependencies
2:27:02 AM: mv: cannot move β€˜/opt/build/cache/.node/corepack’ to β€˜/opt/buildhome/.node/corepack’: No such file or directory
2:27:02 AM: Finished restoring cached corepack dependencies
2:27:03 AM: No npm workspaces detected
2:27:03 AM: Started restoring cached node modules
2:27:03 AM: Finished restoring cached node modules
2:27:03 AM: Bypassing sha validation. Running pre & post install scripts
2:27:03 AM: Installing npm packages using npm version 8.19.3
2:27:10 AM: added 428 packages, and audited 429 packages in 7s
2:27:10 AM: 134 packages are looking for funding
2:27:10 AM: run npm fund for details
2:27:10 AM: found 0 vulnerabilities
2:27:10 AM: npm packages installed
2:27:10 AM: Started restoring cached go cache
2:27:10 AM: Finished restoring cached go cache
2:27:10 AM: go version go1.19.5 linux/amd64
2:27:11 AM: Detected 1 framework(s)
2:27:11 AM: β€œnext” at version β€œ13.1.5”
2:27:11 AM: Installing missing commands
2:27:11 AM: Verify run directory
2:27:11 AM: Section completed: initializing
2:27:12 AM: ​
2:27:12 AM: Netlify Build
2:27:12 AM: ────────────────────────────────────────────────────────────────
2:27:12 AM: ​
2:27:12 AM: ❯ Version
2:27:12 AM: @netlify/build 29.5.1
2:27:12 AM: ​
2:27:12 AM: ❯ Flags
2:27:12 AM: baseRelDir: true
2:27:12 AM: buildId: 63d22b41652d6b15da44a985
2:27:12 AM: deployId: 63d22b41652d6b15da44a987
2:27:12 AM: ​
2:27:12 AM: ❯ Current directory
2:27:12 AM: /opt/build/repo
2:27:12 AM: ​
2:27:12 AM: ❯ Config file
2:27:12 AM: No config file was defined: using default values.
2:27:12 AM: ​
2:27:12 AM: ❯ Context
2:27:12 AM: production
2:27:12 AM: ​
2:27:12 AM: ❯ Using Next.js Runtime - v4.30.2
2:27:14 AM: ​
2:27:14 AM: 1. @netlify/plugin-nextjs (onPreBuild event)
2:27:14 AM: ────────────────────────────────────────────────────────────────
2:27:14 AM: ​
2:27:14 AM: No Next.js cache to restore.
2:27:14 AM: Netlify configuration property β€œbuild.environment.NEXT_PRIVATE_TARGET” value changed.
2:27:14 AM: ​
2:27:14 AM: (@netlify/plugin-nextjs onPreBuild completed in 14ms)
2:27:14 AM: ​
2:27:14 AM: 2. Build command from Netlify app
2:27:14 AM: ────────────────────────────────────────────────────────────────
2:27:14 AM: ​
2:27:14 AM: $ next build
2:27:14 AM: info - Loaded env from /opt/build/repo/.env.local
2:27:14 AM: warn - You have enabled experimental feature (appDir) in next.config.js.
2:27:14 AM: warn - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.
2:27:14 AM: info - Thank you for testing appDir please leave your feedback at https://nextjs.link/app-feedback
2:27:14 AM: warn - No build cache found. Please configure build caching for faster rebuilds. Read more: no-cache | Next.js
2:27:14 AM: > Build error occurred
2:27:14 AM: Error: > Couldn’t find any pages or app directory. Please create one under the project root at Object.findPagesDir (/opt/build/repo/node_modules/next/dist/lib/find-pages-dir.js:76:15)
2:27:14 AM: at /opt/build/repo/node_modules/next/dist/build/index.js:103:63
2:27:14 AM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
2:27:14 AM: at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:66:29)
2:27:14 AM: ​
2:27:14 AM: β€œbuild.command” failed
2:27:14 AM: ────────────────────────────────────────────────────────────────
2:27:14 AM: ​
2:27:15 AM: Failed during stage β€˜building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
2:27:14 AM: Error message
2:27:14 AM: Command failed with exit code 1: next build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
2:27:14 AM: ​
2:27:14 AM: Error location
2:27:14 AM: In Build command from Netlify app:
2:27:14 AM: next build
2:27:14 AM: ​
2:27:14 AM: Resolved config
2:27:14 AM: build:
2:27:14 AM: command: next build
2:27:14 AM: commandOrigin: ui
2:27:14 AM: environment:
2:27:14 AM: - NEXT_PRIVATE_TARGET
2:27:14 AM: publish: /opt/build/repo/.next
2:27:14 AM: publishOrigin: ui
2:27:14 AM: plugins:
2:27:14 AM: - inputs: {}
2:27:14 AM: origin: ui
2:27:14 AM: package: β€˜@netlify/plugin-nextjs’
2:27:14 AM: Caching artifacts
2:27:14 AM: Started saving node modules
2:27:14 AM: Finished saving node modules
2:27:14 AM: Started saving build plugins
2:27:14 AM: Finished saving build plugins
2:27:14 AM: Started saving pip cache
2:27:14 AM: Finished saving pip cache
2:27:14 AM: Started saving emacs cask dependencies
2:27:14 AM: Finished saving emacs cask dependencies
2:27:14 AM: Started saving maven dependencies
2:27:14 AM: Finished saving maven dependencies
2:27:14 AM: Started saving boot dependencies
2:27:14 AM: Finished saving boot dependencies
2:27:14 AM: Started saving rust rustup cache
2:27:14 AM: Finished saving rust rustup cache
2:27:14 AM: Started saving go dependencies
2:27:14 AM: Finished saving go dependencies
2:27:15 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
2:27:15 AM: Failing build: Failed to build site
2:27:15 AM: Finished processing build request in 16.82s

I don’t use Next so can’t assist with a specific answer, but I noticed this forum post mentions experimental.appDir and the need for npm install -D @netlify/plugin-nextjs@appdir…

It’s a few months old now, but maybe it’ll point you in the right direction.

I really appreaciate your time and suggetion but still same error

Base directory
Not set

Build command
npm run build

Publish directory
.next/out/

As the error says…

2:27:14 AM: Error: > Couldn’t find any pages or app directory. 

Checking the repo that is linked in your build log, I can’t see any pages or app directory?

1 Like