Internal error 500 when deploying next.js with SSR

hi, i want to deploy my next.js site on netlify but get this error ‘internal server error 500’ in index page.

*site : https://chic-lamington-54e584.netlify.app/

12:26:34 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
12:26:34 PM: build-image tag: v4.14.3
12:26:34 PM: buildbot version: 4dcf475b8df8e5368becf6538fc83d1d4914f8fc
12:26:34 PM: Fetching cached dependencies
12:26:34 PM: Starting to download cache of 161.4MB
12:26:36 PM: Finished downloading cache in 1.122552425s
12:26:36 PM: Starting to extract cache
12:26:37 PM: Finished extracting cache in 1.614340871s
12:26:37 PM: Finished fetching cache in 2.801204941s
12:26:37 PM: Starting to prepare the repo for build
12:26:37 PM: Preparing Git Reference refs/heads/main
12:26:38 PM: Parsing package.json dependencies
12:26:39 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'out_publish' versus '.next' in the Netlify UI
12:26:39 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'out_functions' versus '' in the Netlify UI
12:26:39 PM: Starting build script
12:26:39 PM: Installing dependencies
12:26:39 PM: Python version set to 2.7
12:26:39 PM: Started restoring cached node version
12:26:40 PM: Finished restoring cached node version
12:26:40 PM: v16.18.1 is already installed.
12:26:40 PM: Now using node v16.18.1 (npm v8.19.2)
12:26:40 PM: Enabling node corepack
12:26:40 PM: Started restoring cached build plugins
12:26:40 PM: Finished restoring cached build plugins
12:26:40 PM: Attempting ruby version 2.7.2, read from environment
12:26:41 PM: Using ruby version 2.7.2
12:26:41 PM: Using PHP version 8.0
12:26:42 PM: No npm workspaces detected
12:26:42 PM: Started restoring cached node modules
12:26:42 PM: Finished restoring cached node modules
12:26:42 PM: Installing NPM modules using NPM version 8.19.2
12:26:44 PM: added 75 packages, and audited 463 packages in 2s
12:26:44 PM: 107 packages are looking for funding
12:26:44 PM:   run `npm fund` for details
12:26:44 PM: found 0 vulnerabilities
12:26:44 PM: NPM modules installed
12:26:44 PM: Creating package sha
12:26:44 PM: Started restoring cached go cache
12:26:44 PM: Finished restoring cached go cache
12:26:44 PM: Installing Go version 1.17 (requested 1.17)
12:26:48 PM: unset GOOS;
12:26:48 PM: unset GOARCH;
12:26:48 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
12:26:48 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
12:26:48 PM: go version >&2;
12:26:48 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
12:26:48 PM: go version go1.17 linux/amd64
12:26:48 PM: Detected 1 framework(s)
12:26:48 PM: "next" at version "12.2.5"
12:26:48 PM: Installing missing commands
12:26:48 PM: Verify run directory
12:26:50 PM: ​
12:26:50 PM: ────────────────────────────────────────────────────────────────
12:26:50 PM:   Netlify Build                                                 
12:26:50 PM: ────────────────────────────────────────────────────────────────
12:26:50 PM: ​
12:26:50 PM: ❯ Version
12:26:50 PM:   @netlify/build 28.1.7
12:26:50 PM: ​
12:26:50 PM: ❯ Flags
12:26:50 PM:   baseRelDir: true
12:26:50 PM:   buildId: 63662540d6dcc20008765657
12:26:50 PM:   deployId: 63662540d6dcc20008765659
12:26:50 PM: ​
12:26:50 PM: ❯ Current directory
12:26:50 PM:   /opt/build/repo
12:26:50 PM: ​
12:26:50 PM: ❯ Config file
12:26:50 PM:   /opt/build/repo/netlify.toml
12:26:50 PM: ​
12:26:50 PM: ❯ Context
12:26:50 PM:   production
12:26:50 PM: ​
12:26:50 PM: ❯ Using Next.js Runtime - v4.21.2
12:26:50 PM: ​
12:26:50 PM: ❯ Outdated plugins
12:26:50 PM:    - @netlify/plugin-nextjs@4.21.2: latest version is 4.28.4
12:26:50 PM:      Migration guide: https://ntl.fyi/next-plugin-migration
12:26:50 PM:      To upgrade this plugin, please update its version in "package.json"
12:26:51 PM: ​
12:26:51 PM: ────────────────────────────────────────────────────────────────
12:26:51 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
12:26:51 PM: ────────────────────────────────────────────────────────────────
12:26:51 PM: ​
12:26:51 PM: No Next.js cache to restore.
12:26:51 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
12:26:51 PM: ​
12:26:51 PM: (@netlify/plugin-nextjs onPreBuild completed in 18ms)
12:26:51 PM: ​
12:26:51 PM: ────────────────────────────────────────────────────────────────
12:26:51 PM:   2. build.command from netlify.toml                            
12:26:51 PM: ────────────────────────────────────────────────────────────────
12:26:51 PM: ​
12:26:51 PM: $ npm run build
12:26:51 PM: > hulu-v2-nextjs@0.1.0 build
12:26:51 PM: > next build
12:26:52 PM: warn  - Invalid next.config.js options detected:
12:26:52 PM:   - The root value has an unexpected property, target, which is not in the list of allowed properties (amp, analyticsId, assetPrefix, basePath, cleanDistDir, compiler, compress, crossOrigin, devIndicators, distDir, env, eslint, excludeDefaultMomentLocales, experimental, exportPathMap, future, generateBuildId, generateEtags, headers, httpAgentOptions, i18n, images, onDemandEntries, optimizeFonts, output, outputFileTracing, pageExtensions, poweredByHeader, productionBrowserSourceMaps, publicRuntimeConfig, reactStrictMode, redirects, rewrites, sassOptions, serverRuntimeConfig, staticPageGenerationTimeout, swcMinify, trailingSlash, typescript, useFileSystemPublicRoutes, webpack).
12:26:52 PM: See more info here: https://nextjs.org/docs/messages/invalid-next-config
12:26:52 PM: warn  - The `target` config is deprecated and will be removed in a future version.
12:26:52 PM: See more info here https://nextjs.org/docs/messages/deprecated-target-config
12:26:52 PM: info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
12:26:52 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
12:26:52 PM: info  - Linting and checking validity of types...
12:26:54 PM: info  - Creating an optimized production build...
12:26:58 PM: info  - Compiled successfully
12:26:58 PM: info  - Collecting page data...
12:27:01 PM: info  - Generating static pages (0/2)
12:27:01 PM: info  - Generating static pages (2/2)
12:27:01 PM: info  - Finalizing page optimization...
12:27:01 PM: Route (pages)                              Size     First Load JS
12:27:01 PM: ┌ λ /                                      12.7 kB        90.5 kB
12:27:01 PM: ├   /_app                                  0 B            77.9 kB
12:27:01 PM: ├ ○ /404                                   186 B          78.1 kB
12:27:01 PM: └ λ /api/hello                             0 B            77.9 kB
12:27:01 PM: + First Load JS shared by all              80.5 kB
12:27:01 PM:   ├ chunks/framework-db825bd0b4ae01ef.js   45.7 kB
12:27:01 PM:   ├ chunks/main-3123a443c688934f.js        30.9 kB
12:27:01 PM:   ├ chunks/pages/_app-0e6b46beaaa55ac1.js  498 B
12:27:01 PM:   ├ chunks/webpack-7ee66019f7f6d30f.js     755 B
12:27:01 PM:   └ css/cdd2203d46214d7c.css               2.65 kB
12:27:01 PM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
12:27:01 PM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
12:27:01 PM: > hulu-v2-nextjs@0.1.0 postbuild
12:27:01 PM: > next-on-netlify
12:27:01 PM: node:internal/modules/cjs/loader:988
12:27:01 PM:   throw err;
12:27:01 PM:   ^
12:27:02 PM: Creating deploy upload records
12:27:01 PM: Error: Cannot find module 'find-cache-dir'
12:27:01 PM: Require stack:
12:27:01 PM: - /opt/build/repo/node_modules/next-on-netlify/lib/steps/prepareFolders.js
12:27:01 PM: - /opt/build/repo/node_modules/next-on-netlify/index.js
12:27:02 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
12:27:01 PM: - /opt/build/repo/node_modules/next-on-netlify/next-on-netlify.js
12:27:01 PM:     at Function.Module._resolveFilename (node:internal/modules/cjs/loader:985:15)
12:27:01 PM:     at Function.Module._load (node:internal/modules/cjs/loader:833:27)
12:27:01 PM:     at Module.require (node:internal/modules/cjs/loader:1057:19)
12:27:01 PM:     at require (node:internal/modules/cjs/helpers:103:18)
12:27:01 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/next-on-netlify/lib/steps/prepareFolders.js:3:22)
12:27:01 PM:     at Module._compile (node:internal/modules/cjs/loader:1155:14)
12:27:01 PM:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
12:27:01 PM:     at Module.load (node:internal/modules/cjs/loader:1033:32)
12:27:01 PM:     at Function.Module._load (node:internal/modules/cjs/loader:868:12)
12:27:01 PM:     at Module.require (node:internal/modules/cjs/loader:1057:19) {
12:27:01 PM:   code: 'MODULE_NOT_FOUND',
12:27:01 PM:   requireStack: [
12:27:01 PM:     '/opt/build/repo/node_modules/next-on-netlify/lib/steps/prepareFolders.js',
12:27:01 PM:     '/opt/build/repo/node_modules/next-on-netlify/index.js',
12:27:01 PM:     '/opt/build/repo/node_modules/next-on-netlify/next-on-netlify.js'
12:27:01 PM:   ]
12:27:01 PM: }
12:27:01 PM: ​
12:27:01 PM: ────────────────────────────────────────────────────────────────
12:27:01 PM:   "build.command" failed                                        
12:27:01 PM: ────────────────────────────────────────────────────────────────
12:27:01 PM: ​
12:27:01 PM:   Error message
12:27:01 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
12:27:01 PM: ​
12:27:01 PM:   Error location
12:27:01 PM:   In build.command from netlify.toml:
12:27:01 PM:   npm run build
12:27:01 PM: ​
12:27:01 PM:   Resolved config
12:27:01 PM:   build:
12:27:01 PM:     command: npm run build
12:27:01 PM:     commandOrigin: config
12:27:01 PM:     environment:
12:27:01 PM:       - NEXT_PRIVATE_TARGET
12:27:01 PM:     publish: /opt/build/repo/out_publish
12:27:01 PM:     publishOrigin: config
12:27:01 PM:   functions:
12:27:01 PM:     '*':
12:27:01 PM:       included_files:
12:27:02 PM:         - public/locales/*  functionsDirectory: /opt/build/repo/out_functions  plugins:    - inputs: {}      origin: ui      package: '@netlify/plugin-nextjs'Caching artifacts
12:27:02 PM: Started saving node modules
12:27:02 PM: Finished saving node modules
12:27:02 PM: Started saving build plugins
12:27:02 PM: Finished saving build plugins
12:27:02 PM: Started saving pip cache
12:27:02 PM: Finished saving pip cache
12:27:02 PM: Started saving emacs cask dependencies
12:27:02 PM: Finished saving emacs cask dependencies
12:27:02 PM: Started saving maven dependencies
12:27:02 PM: Finished saving maven dependencies
12:27:02 PM: Started saving boot dependencies
12:27:02 PM: Finished saving boot dependencies
12:27:02 PM: Started saving rust rustup cache
12:27:02 PM: Finished saving rust rustup cache
12:27:02 PM: Started saving go dependencies
12:27:02 PM: Finished saving go dependencies
12:27:02 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
12:27:02 PM: Failing build: Failed to build site
12:27:02 PM: Finished processing build request in 28.03432268s

Hi @frank1, thanks for posting and welcome.

The highlighted lines above in your deploy logs might be the cause of your errors. Kindly remove the unexpected property target in the next.config.js file to see if it helps resolve the issue.

Let me know the outcome.

Thanks.

@clarnx
i removed that but gets another error for plugin

1:29:07 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
1:29:07 PM: build-image tag: v4.14.3
1:29:07 PM: buildbot version: 4dcf475b8df8e5368becf6538fc83d1d4914f8fc
1:29:07 PM: Fetching cached dependencies
1:29:08 PM: Starting to download cache of 161.4MB
1:29:09 PM: Finished downloading cache in 1.119003729s
1:29:09 PM: Starting to extract cache
1:29:10 PM: Finished extracting cache in 1.212909264s
1:29:10 PM: Finished fetching cache in 2.395890598s
1:29:10 PM: Starting to prepare the repo for build
1:29:10 PM: Preparing Git Reference refs/heads/main
1:29:10 PM: Parsing package.json dependencies
1:29:11 PM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'out_publish' versus '.next' in the Netlify UI
1:29:11 PM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'out_functions' versus '' in the Netlify UI
1:29:12 PM: Starting build script
1:29:12 PM: Installing dependencies
1:29:12 PM: Python version set to 2.7
1:29:12 PM: Started restoring cached node version
1:29:12 PM: Finished restoring cached node version
1:29:13 PM: v16.18.1 is already installed.
1:29:13 PM: Now using node v16.18.1 (npm v8.19.2)
1:29:13 PM: Enabling node corepack
1:29:13 PM: Started restoring cached build plugins
1:29:13 PM: Finished restoring cached build plugins
1:29:13 PM: Attempting ruby version 2.7.2, read from environment
1:29:14 PM: Using ruby version 2.7.2
1:29:14 PM: Using PHP version 8.0
1:29:14 PM: No npm workspaces detected
1:29:14 PM: Started restoring cached node modules
1:29:14 PM: Finished restoring cached node modules
1:29:14 PM: Installing NPM modules using NPM version 8.19.2
1:29:16 PM: added 75 packages, and audited 463 packages in 1s
1:29:16 PM: 107 packages are looking for funding
1:29:16 PM:   run `npm fund` for details
1:29:16 PM: found 0 vulnerabilities
1:29:16 PM: NPM modules installed
1:29:16 PM: Creating package sha
1:29:16 PM: Started restoring cached go cache
1:29:16 PM: Finished restoring cached go cache
1:29:16 PM: Installing Go version 1.17 (requested 1.17)
1:29:22 PM: unset GOOS;
1:29:22 PM: unset GOARCH;
1:29:22 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
1:29:22 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
1:29:22 PM: go version >&2;
1:29:22 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
1:29:22 PM: go version go1.17 linux/amd64
1:29:22 PM: Detected 1 framework(s)
1:29:22 PM: "next" at version "12.2.5"
1:29:22 PM: Installing missing commands
1:29:22 PM: Verify run directory
1:29:23 PM: ​
1:29:23 PM: ────────────────────────────────────────────────────────────────
1:29:23 PM:   Netlify Build                                                 
1:29:23 PM: ────────────────────────────────────────────────────────────────
1:29:23 PM: ​
1:29:23 PM: ❯ Version
1:29:23 PM:   @netlify/build 28.1.7
1:29:23 PM: ​
1:29:23 PM: ❯ Flags
1:29:23 PM:   baseRelDir: true
1:29:23 PM:   buildId: 636633e7193dc14ab6e9c76d
1:29:23 PM:   deployId: 636633e7193dc14ab6e9c76f
1:29:23 PM: ​
1:29:23 PM: ❯ Current directory
1:29:23 PM:   /opt/build/repo
1:29:23 PM: ​
1:29:23 PM: ❯ Config file
1:29:23 PM:   /opt/build/repo/netlify.toml
1:29:23 PM: ​
1:29:23 PM: ❯ Context
1:29:23 PM:   production
1:29:24 PM: ​
1:29:24 PM: ❯ Using Next.js Runtime - v4.21.2
1:29:24 PM: ​
1:29:24 PM: ❯ Outdated plugins
1:29:24 PM:    - @netlify/plugin-nextjs@4.21.2: latest version is 4.28.4
1:29:24 PM:      Migration guide: https://ntl.fyi/next-plugin-migration
1:29:24 PM:      To upgrade this plugin, please update its version in "package.json"
1:29:25 PM: ​
1:29:25 PM: ────────────────────────────────────────────────────────────────
1:29:25 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
1:29:25 PM: ────────────────────────────────────────────────────────────────
1:29:25 PM: ​
1:29:25 PM: No Next.js cache to restore.
1:29:25 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
1:29:25 PM: ​
1:29:25 PM: (@netlify/plugin-nextjs onPreBuild completed in 18ms)
1:29:25 PM: ​
1:29:25 PM: ────────────────────────────────────────────────────────────────
1:29:25 PM:   2. build.command from netlify.toml                            
1:29:25 PM: ────────────────────────────────────────────────────────────────
1:29:25 PM: ​
1:29:25 PM: $ npm run build
1:29:25 PM: > hulu-v2-nextjs@0.1.0 build
1:29:25 PM: > next build
1:29:25 PM: info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
1:29:25 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
1:29:25 PM: info  - Linting and checking validity of types...
1:29:27 PM: info  - Creating an optimized production build...
1:29:31 PM: info  - Compiled successfully
1:29:31 PM: info  - Collecting page data...
1:29:34 PM: info  - Generating static pages (0/2)
1:29:34 PM: info  - Generating static pages (2/2)
1:29:35 PM: info  - Finalizing page optimization...
1:29:35 PM: Route (pages)                              Size     First Load JS
1:29:35 PM: ┌ λ /                                      12.7 kB        90.5 kB
1:29:35 PM: ├   /_app                                  0 B            77.9 kB
1:29:35 PM: ├ ○ /404                                   186 B          78.1 kB
1:29:35 PM: └ λ /api/hello                             0 B            77.9 kB
1:29:35 PM: + First Load JS shared by all              80.5 kB
1:29:35 PM:   ├ chunks/framework-db825bd0b4ae01ef.js   45.7 kB
1:29:35 PM:   ├ chunks/main-3123a443c688934f.js        30.9 kB
1:29:35 PM:   ├ chunks/pages/_app-0e6b46beaaa55ac1.js  498 B
1:29:35 PM:   ├ chunks/webpack-7ee66019f7f6d30f.js     755 B
1:29:35 PM:   └ css/cdd2203d46214d7c.css               2.65 kB
1:29:35 PM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
1:29:35 PM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
1:29:35 PM: ​
1:29:35 PM: (build.command completed in 9.7s)
1:29:35 PM: ​
1:29:35 PM: Creating deploy upload records
1:29:35 PM: ────────────────────────────────────────────────────────────────
1:29:35 PM:   3. @netlify/plugin-nextjs (onBuild event)                     
1:29:35 PM: ────────────────────────────────────────────────────────────────
1:29:35 PM: ​
1:29:35 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:29:35 PM: ​
1:29:35 PM: ────────────────────────────────────────────────────────────────
1:29:35 PM:   Plugin "@netlify/plugin-nextjs" failed                        
1:29:35 PM: ────────────────────────────────────────────────────────────────
1:29:35 PM: ​
1:29:35 PM:   Error message
1:29:35 PM:   Error: The directory "/opt/build/repo/out_publish" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
1:29:35 PM:   However, a '.next' directory was found with a production build.
1:29:35 PM:   Consider changing your 'publish' directory to '.next'
1:29:35 PM:   If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
1:29:35 PM: ​
1:29:35 PM:   Plugin details
1:29:35 PM:   Package:        @netlify/plugin-nextjs
1:29:35 PM:   Version:        4.21.2
1:29:35 PM:   Repository:     git+https://github.com/netlify/next-runtime.git
1:29:35 PM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
1:29:35 PM:   Report issues:  https://github.com/netlify/next-runtime/issues
1:29:35 PM: ​
1:29:35 PM:   Error location
1:29:35 PM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app and package.json
1:29:35 PM: ​
1:29:35 PM:   Resolved config
1:29:35 PM:   build:
1:29:35 PM:     command: npm run build
1:29:35 PM:     commandOrigin: config
1:29:35 PM:     environment:
1:29:35 PM:       - NEXT_PRIVATE_TARGET
1:29:35 PM:     publish: /opt/build/repo/out_publish
1:29:35 PM:     publishOrigin: config
1:29:35 PM:   functions:
1:29:35 PM:     '*':
1:29:35 PM:       included_files:
1:29:35 PM:         - public/locales/*  functionsDirectory: /opt/build/repo/out_functions  plugins:    - inputs: {}      origin: ui      package: '@netlify/plugin-nextjs'Caching artifacts
1:29:35 PM: Started saving node modules
1:29:35 PM: Finished saving node modules
1:29:35 PM: Started saving build plugins
1:29:35 PM: Finished saving build plugins
1:29:35 PM: Started saving pip cache
1:29:35 PM: Finished saving pip cache
1:29:35 PM: Started saving emacs cask dependencies
1:29:35 PM: Finished saving emacs cask dependencies
1:29:35 PM: Started saving maven dependencies
1:29:35 PM: Finished saving maven dependencies
1:29:35 PM: Started saving boot dependencies
1:29:35 PM: Finished saving boot dependencies
1:29:35 PM: Started saving rust rustup cache
1:29:35 PM: Finished saving rust rustup cache
1:29:35 PM: Started saving go dependencies
1:29:35 PM: Finished saving go dependencies
1:29:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:29:35 PM: Failing build: Failed to build site
1:29:35 PM: Finished processing build request in 28.060709036s

Hi @frank1, thanks for the extra information.

If I may ask, are you using Next.js version 4.21.2 on purpose?
If your are not using Next.js version 4.21.2 on purpose kindly update to the latest version on Next.js

Kindly also follow the instructions in the highlighted log above to help you resolve the problem.

If you have tried the above and the problem still exits, if possible kindly share a repository to your site for me to help with the debugging.

Thanks.

thanks @clarnx
this problem solved :slight_smile:

but I have another project that has the same issue, could you check it, please?

site : dancing-wisp-4913d0.netlify.app

3:05:55 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
3:05:55 PM: build-image tag: v4.14.3
3:05:55 PM: buildbot version: 4dcf475b8df8e5368becf6538fc83d1d4914f8fc
3:05:56 PM: Fetching cached dependencies
3:05:56 PM: Failed to fetch cache, continuing with build
3:05:56 PM: Starting to prepare the repo for build
3:05:56 PM: No cached dependencies found. Cloning fresh repo
3:05:56 PM: git clone https://github.com/hadiraz/medium-nextjs
3:06:00 PM: Preparing Git Reference refs/heads/main
3:06:01 PM: Parsing package.json dependencies
3:06:02 PM: Starting build script
3:06:02 PM: Installing dependencies
3:06:02 PM: Python version set to 2.7
3:06:02 PM: Downloading and installing node v16.18.1...
3:06:03 PM: Downloading https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz...
3:06:03 PM: Computing checksum with sha256sum
3:06:03 PM: Checksums matched!
3:06:05 PM: Now using node v16.18.1 (npm v8.19.2)
3:06:05 PM: Enabling node corepack
3:06:05 PM: Started restoring cached build plugins
3:06:05 PM: Finished restoring cached build plugins
3:06:06 PM: Attempting ruby version 2.7.2, read from environment
3:06:06 PM: Using ruby version 2.7.2
3:06:06 PM: Using PHP version 8.0
3:06:07 PM: No npm workspaces detected
3:06:07 PM: Started restoring cached node modules
3:06:07 PM: Finished restoring cached node modules
3:06:07 PM: Installing NPM modules using NPM version 8.19.2
3:06:25 PM: added 612 packages, and audited 613 packages in 18s
3:06:25 PM: 121 packages are looking for funding
3:06:25 PM:   run `npm fund` for details
3:06:25 PM: found 0 vulnerabilities
3:06:25 PM: NPM modules installed
3:06:25 PM: Creating package sha
3:06:25 PM: Started restoring cached go cache
3:06:25 PM: Finished restoring cached go cache
3:06:25 PM: Installing Go version 1.17 (requested 1.17)
3:06:29 PM: unset GOOS;
3:06:29 PM: unset GOARCH;
3:06:29 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
3:06:29 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
3:06:29 PM: go version >&2;
3:06:29 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
3:06:29 PM: go version go1.17 linux/amd64
3:06:30 PM: Detected 1 framework(s)
3:06:30 PM: "next" at version "12.2.5"
3:06:30 PM: Installing missing commands
3:06:30 PM: Verify run directory
3:06:31 PM: ​
3:06:31 PM: ────────────────────────────────────────────────────────────────
3:06:31 PM:   Netlify Build                                                 
3:06:31 PM: ────────────────────────────────────────────────────────────────
3:06:31 PM: ​
3:06:31 PM: ❯ Version
3:06:31 PM:   @netlify/build 28.1.7
3:06:31 PM: ​
3:06:31 PM: ❯ Flags
3:06:31 PM:   baseRelDir: true
3:06:31 PM:   buildId: 63664a8ce7f0735bd5228e8c
3:06:31 PM:   deployId: 63664a8ce7f0735bd5228e8e
3:06:31 PM: ​
3:06:31 PM: ❯ Current directory
3:06:31 PM:   /opt/build/repo
3:06:31 PM: ​
3:06:31 PM: ❯ Config file
3:06:31 PM:   No config file was defined: using default values.
3:06:31 PM: ​
3:06:31 PM: ❯ Context
3:06:31 PM:   production
3:06:31 PM: ​
3:06:31 PM: ❯ Using Next.js Runtime - v4.28.4
3:06:32 PM: ​
3:06:32 PM: ────────────────────────────────────────────────────────────────
3:06:32 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
3:06:32 PM: ────────────────────────────────────────────────────────────────
3:06:32 PM: ​
3:06:32 PM: No Next.js cache to restore.
3:06:32 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
3:06:32 PM: ​
3:06:32 PM: (@netlify/plugin-nextjs onPreBuild completed in 14ms)
3:06:32 PM: ​
3:06:32 PM: ────────────────────────────────────────────────────────────────
3:06:32 PM:   2. Build command from Netlify app                             
3:06:32 PM: ────────────────────────────────────────────────────────────────
3:06:32 PM: ​
3:06:32 PM: $ npm run build
3:06:33 PM: > medium@0.1.0 build
3:06:33 PM: > next build
3:06:33 PM: info  - SWC minify release candidate enabled. https://nextjs.link/swcmin
3:06:33 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
3:06:33 PM: info  - Linting and checking validity of types...
3:06:35 PM: ./pages/index.js
3:06:35 PM: 30:11  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
3:06:35 PM: 39:37  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
3:06:35 PM: 41:42  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
3:06:35 PM: ./pages/post/[slug].js
3:06:35 PM: 29:13  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
3:06:35 PM: 34:21  Warning: Do not use `<img>` element. Use `<Image />` from `next/image` instead. See: https://nextjs.org/docs/messages/no-img-element  @next/next/no-img-element
3:06:35 PM: 34:21  Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images.  jsx-a11y/alt-text
3:06:35 PM: info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
3:06:35 PM: info  - Creating an optimized production build...
3:06:39 PM: info  - Compiled successfully
3:06:39 PM: info  - Collecting page data...
3:06:40 PM: Error: Configuration must contain `projectId`
3:06:40 PM:     at exports.initConfig (/opt/build/repo/node_modules/@sanity/client/lib/config.js:42:11)
3:06:40 PM:     at SanityClient.config (/opt/build/repo/node_modules/@sanity/client/lib/sanityClient.js:85:25)
3:06:40 PM:     at new SanityClient (/opt/build/repo/node_modules/@sanity/client/lib/sanityClient.js:53:8)
3:06:40 PM:     at SanityClient (/opt/build/repo/node_modules/@sanity/client/lib/sanityClient.js:50:12)
3:06:40 PM:     at exports.createClient (/opt/build/repo/node_modules/next-sanity/dist/next-sanity.cjs.production.min.js:1:1023)
3:06:40 PM:     at Object.3774 (/opt/build/repo/.next/server/chunks/1.js:97:79)
3:06:40 PM:     at __webpack_require__ (/opt/build/repo/.next/server/webpack-runtime.js:25:42)
3:06:40 PM:     at Object.304 (/opt/build/repo/.next/server/pages/index.js:28:14)
3:06:40 PM:     at __webpack_require__ (/opt/build/repo/.next/server/webpack-runtime.js:25:42)
3:06:40 PM:     at __webpack_exec__ (/opt/build/repo/.next/server/pages/index.js:374:39)
3:06:40 PM: Error: Configuration must contain `projectId`
3:06:40 PM:     at exports.initConfig (/opt/build/repo/node_modules/@sanity/client/lib/config.js:42:11)
3:06:40 PM:     at SanityClient.config (/opt/build/repo/node_modules/@sanity/client/lib/sanityClient.js:85:25)
3:06:40 PM:     at new SanityClient (/opt/build/repo/node_modules/@sanity/client/lib/sanityClient.js:53:8)
3:06:40 PM:     at SanityClient (/opt/build/repo/node_modules/@sanity/client/lib/sanityClient.js:50:12)
3:06:40 PM:     at exports.createClient (/opt/build/repo/node_modules/next-sanity/dist/next-sanity.cjs.production.min.js:1:1023)
3:06:40 PM:     at Object.3774 (/opt/build/repo/.next/server/chunks/1.js:97:79)
3:06:40 PM:     at __webpack_require__ (/opt/build/repo/.next/server/webpack-runtime.js:25:42)
3:06:40 PM:     at /opt/build/repo/.next/server/pages/post/[slug].js:23:65
3:06:40 PM:     at Function.__webpack_require__.a (/opt/build/repo/.next/server/webpack-runtime.js:89:13)
3:06:40 PM:     at Object.7016 (/opt/build/repo/.next/server/pages/post/[slug].js:11:21)
3:06:40 PM: > Build error occurred
3:06:40 PM: Error: Failed to collect page data for /
3:06:40 PM:     at /opt/build/repo/node_modules/next/dist/build/utils.js:743:15
3:06:40 PM:     at processTicksAndRejections (node:internal/process/task_queues:96:5) {
3:06:40 PM:   type: 'Error'
3:06:40 PM: }
3:06:40 PM: ​
3:06:40 PM: ────────────────────────────────────────────────────────────────
3:06:40 PM:   "build.command" failed                                        
3:06:40 PM: ────────────────────────────────────────────────────────────────
3:06:40 PM: ​
3:06:40 PM:   Error message
3:06:40 PM:   Command failed with exit code 1: npm run build
3:06:40 PM: ​
3:06:40 PM:   Error location
3:06:40 PM:   In Build command from Netlify app:
3:06:41 PM: Creating deploy upload records
3:06:40 PM:   npm run build
3:06:40 PM: ​
3:06:40 PM:   Resolved config
3:06:40 PM:   build:
3:06:40 PM:     command: npm run build
3:06:41 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
3:06:40 PM:     commandOrigin: ui
3:06:40 PM:     environment:
3:06:40 PM:       - NEXT_PRIVATE_TARGET
3:06:40 PM:     publish: /opt/build/repo/.next
3:06:40 PM:     publishOrigin: ui
3:06:40 PM:   plugins:
3:06:40 PM:     - inputs: {}
3:06:40 PM:       origin: ui
3:06:40 PM:       package: '@netlify/plugin-nextjs'
3:06:40 PM: Caching artifacts
3:06:40 PM: Started saving node modules
3:06:40 PM: Finished saving node modules
3:06:40 PM: Started saving build plugins
3:06:40 PM: Finished saving build plugins
3:06:40 PM: Started saving pip cache
3:06:40 PM: Finished saving pip cache
3:06:40 PM: Started saving emacs cask dependencies
3:06:40 PM: Finished saving emacs cask dependencies
3:06:40 PM: Started saving maven dependencies
3:06:40 PM: Finished saving maven dependencies
3:06:40 PM: Started saving boot dependencies
3:06:40 PM: Finished saving boot dependencies
3:06:40 PM: Started saving rust rustup cache
3:06:40 PM: Finished saving rust rustup cache
3:06:40 PM: Started saving go dependencies
3:06:40 PM: Finished saving go dependencies
3:06:41 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:06:41 PM: Failing build: Failed to build site
3:06:41 PM: Finished processing build request in 45.822071429s

Hi @frank1, glad the suggestions helped fix your problem in your first project.

Regarding the second project kindly fix the highlighted errors in the deploy logs below.

Kindly update Next.js to the latest version

The error above comes up when you’re missing the projectId. You have to use projectId when creating your Sanity client instance.

Check the sample configuration below.

const client = sanityClient({
  projectId: 'your project-id',
  dataset: 'your dataset',
  token: 'Sanity build token',
  apiVersion: 'v1',
  useCdn: false // `false` if you want to ensure fresh data
})

Let me know the outcome after fixing the errors stated above.

Thanks.

1 Like

@clarnx
Thank you very much, the problem is solved
Thanks for your time and quick reply :slight_smile:

1 Like

Hi, i have the same problem. Can you please help me to figure it out?
I don’t know if it helps, but i’m using the environment variable NETLIFY_NEXT_PLUGIN_SKIP=false on netlify, and the version of next.js is 4.28.4 both in netlify and in mine package.json. If needed you can check my repo at ruanmello1/personalBlogFrontend (github.com)

1:18:05 AM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
1:18:05 AM: build-image tag: v4.14.3
1:18:05 AM: buildbot version: 4dcf475b8df8e5368becf6538fc83d1d4914f8fc
1:18:05 AM: Fetching cached dependencies
1:18:05 AM: Starting to download cache of 187.7MB
1:18:06 AM: Finished downloading cache in 521.701223ms
1:18:06 AM: Starting to extract cache
1:18:07 AM: Finished extracting cache in 1.314745152s
1:18:07 AM: Finished fetching cache in 1.876050714s
1:18:07 AM: Starting to prepare the repo for build
1:18:07 AM: Preparing Git Reference refs/heads/main
1:18:08 AM: Parsing package.json dependencies
1:18:09 AM: Different publish path detected, going to use the one specified in the Netlify configuration file: 'out_publish' versus '.next/' in the Netlify UI
1:18:09 AM: Different functions path detected, going to use the one specified in the Netlify configuration file: 'out_functions' versus '' in the Netlify UI
1:18:09 AM: Different build command detected, going to use the one specified in the Netlify configuration file: 'CI= npm run build' versus '' in the Netlify UI
1:18:09 AM: Starting build script
1:18:09 AM: Installing dependencies
1:18:09 AM: Python version set to 2.7
1:18:09 AM: Started restoring cached node version
1:18:10 AM: Finished restoring cached node version
1:18:10 AM: v16.18.1 is already installed.
1:18:11 AM: Now using node v16.18.1 (npm v8.19.2)
1:18:11 AM: Enabling node corepack
1:18:11 AM: Started restoring cached build plugins
1:18:11 AM: Finished restoring cached build plugins
1:18:11 AM: Attempting ruby version 2.7.2, read from environment
1:18:11 AM: Using ruby version 2.7.2
1:18:12 AM: Using PHP version 8.0
1:18:12 AM: No npm workspaces detected
1:18:12 AM: Started restoring cached node modules
1:18:12 AM: Finished restoring cached node modules
1:18:12 AM: Installing NPM modules using NPM version 8.19.2
1:18:16 AM: added 126 packages, and audited 499 packages in 3s
1:18:16 AM: 167 packages are looking for funding
1:18:16 AM:   run `npm fund` for details
1:18:16 AM: found 0 vulnerabilities
1:18:16 AM: NPM modules installed
1:18:16 AM: Creating package sha
1:18:16 AM: Started restoring cached go cache
1:18:16 AM: Finished restoring cached go cache
1:18:16 AM: Installing Go version 1.17 (requested 1.17)
1:18:21 AM: unset GOOS;
1:18:21 AM: unset GOARCH;
1:18:21 AM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
1:18:21 AM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
1:18:21 AM: go version >&2;
1:18:21 AM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
1:18:21 AM: go version go1.17 linux/amd64
1:18:21 AM: Detected 1 framework(s)
1:18:22 AM: "next" at version "13.0.2"
1:18:22 AM: Installing missing commands
1:18:22 AM: Verify run directory
1:18:23 AM: ​
1:18:23 AM: ────────────────────────────────────────────────────────────────
1:18:23 AM:   Netlify Build                                                 
1:18:23 AM: ────────────────────────────────────────────────────────────────
1:18:23 AM: ​
1:18:23 AM: ❯ Version
1:18:23 AM:   @netlify/build 28.1.7
1:18:23 AM: ​
1:18:23 AM: ❯ Flags
1:18:23 AM:   baseRelDir: true
1:18:23 AM:   buildId: 636886f939a2406c8eea73ea
1:18:23 AM:   deployId: 636886f939a2406c8eea73ec
1:18:23 AM: ​
1:18:23 AM: ❯ Current directory
1:18:23 AM:   /opt/build/repo
1:18:23 AM: ​
1:18:23 AM: ❯ Config file
1:18:23 AM:   /opt/build/repo/netlify.toml
1:18:23 AM: ​
1:18:23 AM: ❯ Context
1:18:23 AM:   production
1:18:23 AM: ​
1:18:23 AM: ❯ Using Next.js Runtime - v4.28.4
1:18:24 AM: ​
1:18:24 AM: ────────────────────────────────────────────────────────────────
1:18:24 AM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
1:18:24 AM: ────────────────────────────────────────────────────────────────
1:18:24 AM: ​
1:18:24 AM: No Next.js cache to restore.
1:18:24 AM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
1:18:24 AM: ​
1:18:24 AM: (@netlify/plugin-nextjs onPreBuild completed in 21ms)
1:18:24 AM: ​
1:18:24 AM: ────────────────────────────────────────────────────────────────
1:18:24 AM:   2. build.command from netlify.toml                            
1:18:24 AM: ────────────────────────────────────────────────────────────────
1:18:24 AM: ​
1:18:24 AM: $ CI= npm run build
1:18:25 AM: > blog-next@0.1.0 build
1:18:25 AM: > next build
1:18:25 AM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
1:18:25 AM: info  - Linting and checking validity of types...
1:18:26 AM: warn  - The Next.js plugin was not detected in your ESLint configuration. See https://nextjs.org/docs/basic-features/eslint#migrating-existing-config
1:18:26 AM: Warning: React version not specified in eslint-plugin-react settings. See https://github.com/jsx-eslint/eslint-plugin-react#configuration .
1:18:28 AM: ./src/components/Footer/index.tsx
1:18:28 AM: 1:8  Warning: 'Link' is defined but never used.  @typescript-eslint/no-unused-vars
1:18:28 AM: ./src/data/posts/get-post.ts
1:18:28 AM: 1:10  Warning: 'json' is defined but never used.  @typescript-eslint/no-unused-vars
1:18:28 AM: info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
1:18:28 AM: info  - Creating an optimized production build...
1:18:29 AM: info  - Disabled SWC as replacement for Babel because of custom Babel configuration ".babelrc.js" https://nextjs.org/docs/messages/swc-disabled
1:18:29 AM: info  - Using external babel configuration from /opt/build/repo/.babelrc.js
1:18:35 AM: info  - Compiled successfully
1:18:35 AM: info  - Collecting page data...
1:18:40 AM: info  - Generating static pages (0/12)
1:18:41 AM: info  - Generating static pages (3/12)
1:18:41 AM: {
1:18:41 AM:   id: 3,
1:18:41 AM:   name: 'Ana Letícia',
1:18:41 AM:   published_at: '2022-11-06T16:04:55.226Z',
1:18:41 AM:   created_at: '2022-11-04T02:42:54.606Z',
1:18:41 AM:   updated_at: '2022-11-06T16:04:55.247Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 2,
1:18:41 AM:   name: 'João Marcelo',
1:18:41 AM:   published_at: '2022-11-06T16:04:51.882Z',
1:18:41 AM:   created_at: '2022-11-04T02:41:30.724Z',
1:18:41 AM:   updated_at: '2022-11-06T16:04:51.909Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 2,
1:18:41 AM:   name: 'João Marcelo',
1:18:41 AM:   published_at: '2022-11-06T16:04:51.882Z',
1:18:41 AM:   created_at: '2022-11-04T02:41:30.724Z',
1:18:41 AM:   updated_at: '2022-11-06T16:04:51.909Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 3,
1:18:41 AM:   name: 'Ana Letícia',
1:18:41 AM:   published_at: '2022-11-06T16:04:55.226Z',
1:18:41 AM:   created_at: '2022-11-04T02:42:54.606Z',
1:18:41 AM:   updated_at: '2022-11-06T16:04:55.247Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 1,
1:18:41 AM:   name: 'Ruan Mello',
1:18:41 AM:   published_at: '2022-11-06T16:03:37.981Z',
1:18:42 AM: Creating deploy upload records
1:18:41 AM:   created_at: '2022-11-04T01:56:39.759Z',
1:18:41 AM:   updated_at: '2022-11-06T16:03:38.007Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 1,
1:18:42 AM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
1:18:41 AM:   name: 'Ruan Mello',
1:18:41 AM:   published_at: '2022-11-06T16:03:37.981Z',
1:18:41 AM:   created_at: '2022-11-04T01:56:39.759Z',
1:18:41 AM:   updated_at: '2022-11-06T16:03:38.007Z'
1:18:41 AM: }
1:18:41 AM: info  - Generating static pages (6/12)
1:18:41 AM: {
1:18:41 AM:   id: 3,
1:18:41 AM:   name: 'Ana Letícia',
1:18:41 AM:   published_at: '2022-11-06T16:04:55.226Z',
1:18:41 AM:   created_at: '2022-11-04T02:42:54.606Z',
1:18:41 AM:   updated_at: '2022-11-06T16:04:55.247Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 1,
1:18:41 AM:   name: 'Ruan Mello',
1:18:41 AM:   published_at: '2022-11-06T16:03:37.981Z',
1:18:41 AM:   created_at: '2022-11-04T01:56:39.759Z',
1:18:41 AM:   updated_at: '2022-11-06T16:03:38.007Z'
1:18:41 AM: }
1:18:41 AM: {
1:18:41 AM:   id: 2,
1:18:41 AM:   name: 'João Marcelo',
1:18:41 AM:   published_at: '2022-11-06T16:04:51.882Z',
1:18:41 AM:   created_at: '2022-11-04T02:41:30.724Z',
1:18:41 AM:   updated_at: '2022-11-06T16:04:51.909Z'
1:18:41 AM: }
1:18:41 AM: info  - Generating static pages (9/12)
1:18:41 AM: info  - Generating static pages (12/12)
1:18:41 AM: info  - Finalizing page optimization...
1:18:41 AM: Route (pages)                              Size     First Load JS
1:18:41 AM: ┌ ● / (885 ms)                             1.37 kB        97.2 kB
1:18:41 AM: ├   /_app                                  0 B            92.6 kB
1:18:41 AM: ├ ○ /404                                   2.67 kB        95.3 kB
1:18:41 AM: ├ λ /categories/[category]                 1.39 kB        97.2 kB
1:18:41 AM: └ ● /post/[slug] (10769 ms)                5.79 kB         102 kB
1:18:41 AM:     ├ /post/post-exemplo-3 (1282 ms)
1:18:41 AM:     ├ /post/post-exemplo-4 (1237 ms)
1:18:41 AM:     ├ /post/post-exemplo-7 (1222 ms)
1:18:41 AM:     ├ /post/post-exemplo-2 (1218 ms)
1:18:41 AM:     ├ /post/post-exemplo-9 (1215 ms)
1:18:41 AM:     ├ /post/post-exemplo-6 (1184 ms)
1:18:41 AM:     ├ /post/post-exemplo-8 (1160 ms)
1:18:41 AM:     └ [+2 more paths] (avg 1126 ms)
1:18:41 AM: + First Load JS shared by all              92.6 kB
1:18:41 AM:   ├ chunks/framework-3b5a00d5d7e8d93b.js   45.4 kB
1:18:41 AM:   ├ chunks/main-7a6f05985b541054.js        30.7 kB
1:18:41 AM:   ├ chunks/pages/_app-44753b4d80f60111.js  14.9 kB
1:18:41 AM:   └ chunks/webpack-ab2a936dacd21e37.js     1.6 kB
1:18:41 AM: λ  (Server)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
1:18:41 AM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
1:18:41 AM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
1:18:41 AM: ​
1:18:41 AM: (build.command completed in 17s)
1:18:41 AM: ​
1:18:41 AM: ────────────────────────────────────────────────────────────────
1:18:41 AM:   3. @netlify/plugin-nextjs (onBuild event)                     
1:18:41 AM: ────────────────────────────────────────────────────────────────
1:18:41 AM: ​
1:18:42 AM: ​
1:18:42 AM: ────────────────────────────────────────────────────────────────
1:18:42 AM:   Plugin "@netlify/plugin-nextjs" failed                        
1:18:42 AM: ────────────────────────────────────────────────────────────────
1:18:42 AM: ​
1:18:42 AM:   Error message
1:18:42 AM:   Error: The directory "/opt/build/repo/out_publish" does not contain a Next.js production build. Perhaps the build command was not run, or you specified the wrong publish directory.
1:18:42 AM:   However, a '.next' directory was found with a production build.
1:18:42 AM:   Consider changing your 'publish' directory to '.next'
1:18:42 AM:   If you are using "next export" then you should set the environment variable NETLIFY_NEXT_PLUGIN_SKIP to "true".
1:18:42 AM: ​
1:18:42 AM:   Plugin details
1:18:42 AM:   Package:        @netlify/plugin-nextjs
1:18:42 AM:   Version:        4.28.4
1:18:42 AM:   Repository:     git+https://github.com/netlify/next-runtime.git
1:18:42 AM:   npm link:       https://www.npmjs.com/package/@netlify/plugin-nextjs
1:18:42 AM:   Report issues:  https://github.com/netlify/next-runtime/issues
1:18:42 AM: ​
1:18:42 AM:   Error location
1:18:42 AM:   In "onBuild" event in "@netlify/plugin-nextjs" from Netlify app and package.json
1:18:42 AM: ​
1:18:42 AM:   Resolved config
1:18:42 AM:   build:
1:18:42 AM:     command: CI= npm run build
1:18:42 AM:     commandOrigin: config
1:18:42 AM:     environment:
1:18:42 AM:       - NETLIFY_NEXT_PLUGIN_SKIP
1:18:42 AM:       - NEXT_PRIVATE_TARGET
1:18:42 AM:     publish: /opt/build/repo/out_publish
1:18:42 AM:     publishOrigin: config
1:18:42 AM:   functionsDirectory: /opt/build/repo/out_functions
1:18:42 AM:   plugins:
1:18:42 AM:     - inputs: {}
1:18:42 AM:       origin: ui
1:18:42 AM:       package: '@netlify/plugin-nextjs'
1:18:42 AM: Caching artifacts
1:18:42 AM: Started saving node modules
1:18:42 AM: Finished saving node modules
1:18:42 AM: Started saving build plugins
1:18:42 AM: Finished saving build plugins
1:18:42 AM: Started saving pip cache
1:18:42 AM: Finished saving pip cache
1:18:42 AM: Started saving emacs cask dependencies
1:18:42 AM: Finished saving emacs cask dependencies
1:18:42 AM: Started saving maven dependencies
1:18:42 AM: Finished saving maven dependencies
1:18:42 AM: Started saving boot dependencies
1:18:42 AM: Finished saving boot dependencies
1:18:42 AM: Started saving rust rustup cache
1:18:42 AM: Finished saving rust rustup cache
1:18:42 AM: Started saving go dependencies
1:18:42 AM: Finished saving go dependencies
1:18:42 AM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:18:42 AM: Failing build: Failed to build site
1:18:42 AM: Finished processing build request in 37.015363076s

Hi @ruanmello1,

First of all update Next.js to the latest version.

Also Based on your build log, you’re using Next.js’ static export.
You need to add NETLIFY_NEXT_PLUGIN_SKIP environment variable with the value true in the Netlify UI.
You can find more information about the above at the link below.

Hope this helps.
Thanks

1 Like