Home
Support Forums

Netlify NextJs deployment fails

I am not able to deploy my nextjs application on netlify.
The site’s name Is happy-williams-f624b0

I added a netlify.toml file

Which looks like this:

[build]
  command = "next build && next export"
  publish = "out"

This is the error part:

11:10:32 PM: ────────────────────────────────────────────────────────────────
11:10:32 PM:   "build.command" failed                                        
11:10:32 PM: ────────────────────────────────────────────────────────────────
11:10:32 PM: ​
11:10:32 PM:   Error message
11:10:32 PM:   Command failed with exit code 1: next build && next export
11:10:32 PM: ​
11:10:32 PM:   Error location
11:10:32 PM:   In build.command from netlify.toml:
11:10:32 PM:   next build && next export
11:10:32 PM: ​
11:10:32 PM:   Resolved config
11:10:32 PM:   build:
11:10:32 PM:     command: next build && next export
11:10:32 PM:     commandOrigin: config
11:10:32 PM:     publish: /opt/build/repo/out
11:10:32 PM:     publishOrigin: config
11:10:32 PM:   plugins:
11:10:32 PM:     - inputs: {}
11:10:32 PM:       origin: ui
11:10:32 PM:       package: '@netlify/plugin-nextjs'

This is the full deployment log:

11:08:34 PM: Build ready to start
11:08:36 PM: build-image version: fa439ad1ab9393b2c0d449d8d7c033927683f4b0
11:08:36 PM: build-image tag: v4.3.0
11:08:36 PM: buildbot version: 1ed4041128c7c024b4c4b72e2ad30a0740c570a7
11:08:36 PM: Fetching cached dependencies
11:08:36 PM: Failed to fetch cache, continuing with build
11:08:36 PM: Starting to prepare the repo for build
11:08:37 PM: No cached dependencies found. Cloning fresh repo
11:08:37 PM: git clone https://github.com/28development/persona_imo
11:08:38 PM: Preparing Git Reference refs/heads/main
11:08:38 PM: Parsing package.json dependencies
11:08:39 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'next build && next export' versus 'next build' in the Netlify UI
11:08:39 PM: Starting build script
11:08:39 PM: Installing dependencies
11:08:39 PM: Python version set to 2.7
11:08:40 PM: Downloading and installing node v16.8.0...
11:08:40 PM: Downloading https://nodejs.org/dist/v16.8.0/node-v16.8.0-linux-x64.tar.xz...
11:08:40 PM: Computing checksum with sha256sum
11:08:40 PM: Checksums matched!
11:08:43 PM: Now using node v16.8.0 (npm v7.21.0)
11:08:43 PM: Started restoring cached build plugins
11:08:43 PM: Finished restoring cached build plugins
11:08:43 PM: Attempting ruby version 2.7.2, read from environment
11:08:45 PM: Using ruby version 2.7.2
11:08:45 PM: Using PHP version 8.0
11:08:45 PM: Started restoring cached node modules
11:08:45 PM: Finished restoring cached node modules
11:08:45 PM: Installing NPM modules using NPM version 7.21.0
11:08:57 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
11:09:07 PM: npm WARN deprecated @types/vfile-message@2.0.0: This is a stub types definition. vfile-message provides its own type definitions, so you do not need this installed.
11:09:08 PM: npm WARN deprecated @hapi/pinpoint@1.0.2: Moved to 'npm install @sideway/pinpoint'
11:09:08 PM: npm WARN deprecated @hapi/formula@1.2.0: Moved to 'npm install @sideway/formula'
11:09:08 PM: npm WARN deprecated @hapi/topo@3.1.6: This version has been deprecated and is no longer supported or maintained
11:09:09 PM: npm WARN deprecated @hapi/address@2.1.4: Moved to 'npm install @sideway/address'
11:09:10 PM: npm WARN deprecated @hapi/bourne@1.3.2: This version has been deprecated and is no longer supported or maintained
11:09:10 PM: npm WARN deprecated @hapi/boom@7.4.11: This version has been deprecated and is no longer supported or maintained
11:09:11 PM: npm WARN deprecated @hapi/wreck@15.1.0: This version has been deprecated and is no longer supported or maintained
11:09:11 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
11:09:12 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
11:09:12 PM: npm WARN deprecated @hapi/hoek@8.5.1: This version has been deprecated and is no longer supported or maintained
11:09:12 PM: npm WARN deprecated @hapi/joi@16.1.8: Switch to 'npm install joi'
11:09:40 PM: > personaimo@1.1.0 prepare
11:09:40 PM: > husky install
11:09:40 PM: husky - Git hooks installed
11:09:40 PM: added 1612 packages, and audited 1613 packages in 54s
11:09:40 PM: 72 packages are looking for funding
11:09:40 PM:   run `npm fund` for details
11:09:40 PM: 6 high severity vulnerabilities
11:09:40 PM: To address issues that do not require attention, run:
11:09:40 PM:   npm audit fix
11:09:40 PM: Some issues need review, and may require choosing
11:09:40 PM: a different dependency.
11:09:40 PM: Run `npm audit` for details.
11:09:40 PM: NPM modules installed
11:09:40 PM: Started restoring cached go cache
11:09:40 PM: Finished restoring cached go cache
11:09:40 PM: go version go1.16.5 linux/amd64
11:09:40 PM: go version go1.16.5 linux/amd64
11:09:40 PM: Installing missing commands
11:09:40 PM: Verify run directory
11:09:41 PM: ​
11:09:41 PM: ────────────────────────────────────────────────────────────────
11:09:41 PM:   Netlify Build                                                 
11:09:41 PM: ────────────────────────────────────────────────────────────────
11:09:41 PM: ​
11:09:41 PM: ❯ Version
11:09:41 PM:   @netlify/build 18.7.3
11:09:41 PM: ​
11:09:41 PM: ❯ Flags
11:09:41 PM:   baseRelDir: true
11:09:41 PM:   buildId: 61313d528f6fb800072a65ab
11:09:41 PM:   deployId: 61313d528f6fb800072a65ad
11:09:41 PM: ​
11:09:41 PM: ❯ Current directory
11:09:41 PM:   /opt/build/repo
11:09:41 PM: ​
11:09:41 PM: ❯ Config file
11:09:41 PM:   /opt/build/repo/netlify.toml
11:09:41 PM: ​
11:09:41 PM: ❯ Context
11:09:41 PM:   production
11:09:42 PM: ​
11:09:42 PM: ❯ Installing plugins
11:09:42 PM:    - @netlify/plugin-nextjs@3.9.0
11:09:50 PM: ​
11:09:50 PM: ❯ Loading plugins
11:09:50 PM:    - @netlify/plugin-nextjs@3.9.0 from Netlify app
11:09:51 PM: ​
11:09:51 PM: ────────────────────────────────────────────────────────────────
11:09:51 PM:   1. onPreBuild command from @netlify/plugin-nextjs             
11:09:51 PM: ────────────────────────────────────────────────────────────────
11:09:51 PM: ​
11:09:51 PM: Using Next.js 11.1.0
11:09:51 PM: Warning: support for Next.js >=11.1.0 is experimental
11:09:51 PM: NOTE: Static HTML export Next.js projects (projects that use `next export`) do not require most of this plugin. For these sites, this plugin *only* caches builds.
11:09:51 PM: ​
11:09:51 PM: (@netlify/plugin-nextjs onPreBuild completed in 15ms)
11:09:51 PM: ​
11:09:51 PM: ────────────────────────────────────────────────────────────────
11:09:51 PM:   2. build.command from netlify.toml                            
11:09:51 PM: ────────────────────────────────────────────────────────────────
11:09:51 PM: ​
11:09:51 PM: $ next build && next export
11:09:51 PM: info  - Loaded env from /opt/build/repo/.env
11:09:52 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
11:09:52 PM: warn  - You have enabled experimental feature(s).
11:09:52 PM: warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.
11:09:52 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
11:09:52 PM: info  - Checking validity of types...
11:09:55 PM: info  - Creating an optimized production build...
11:10:01 PM: warn - You have enabled the JIT engine which is currently in preview.
11:10:01 PM: warn - Preview features are not covered by semver, may introduce breaking changes, and can change at any time.
11:10:18 PM: (node:1799) [DEP_WEBPACK_CHUNK_HAS_ENTRY_MODULE] DeprecationWarning: Chunk.hasEntryModule: Use new ChunkGraph API
11:10:18 PM: (Use `node --trace-deprecation ...` to show where the warning was created)
11:10:18 PM: (node:1799) [DEP_WEBPACK_CHUNK_ADD_MODULE] DeprecationWarning: Chunk.addModule: Use new ChunkGraph API
11:10:22 PM: warn  - Compiled with warnings
11:10:22 PM: ./node_modules/keyv/src/index.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: ./node_modules/next/dist/server/load-components.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: ./node_modules/next/dist/server/load-components.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: ./node_modules/next/dist/server/load-components.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: ./node_modules/next/dist/server/require.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: ./node_modules/next/dist/server/require.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: ./node_modules/next/dist/server/require.js
11:10:22 PM: Critical dependency: the request of a dependency is an expression
11:10:22 PM: info  - Collecting page data...
11:10:26 PM: info  - Generating static pages (0/12)
11:10:29 PM: [{"slug":"haus-am-see-dortmund","title":"Haus Am See Dortmund","date":"2021-08-22T00:00:00.000Z","galleryImages":["/img/avatar.png"],"tag":["Haus","See"],"tags":["Haus","See"]},{"slug":"haus-am-see-essen","title":"Haus Am See Essen","date":"2021-08-22T00:00:00.000Z","galleryImages":["/img/avatar.png"],"tag":["Haus","See"],"tags":["Haus","See"]}]
11:10:30 PM: info  - Generating static pages (3/12)
11:10:30 PM: info  - Generating static pages (6/12)
11:10:30 PM: info  - Generating static pages (9/12)
11:10:31 PM: info  - Generating static pages (12/12)
11:10:31 PM: info  - Finalizing page optimization...
11:10:31 PM: Page                                               Size     First Load JS
11:10:31 PM: ┌ ● / (3202 ms)                                    2.12 kB        42.7 kB
11:10:31 PM: ├   /_app                                          0 B            40.6 kB
11:10:31 PM: ├ ○ /404 (600 ms)                                  703 B          41.3 kB
11:10:31 PM: ├ ● /about (3729 ms)                               346 B          50.1 kB
11:10:31 PM: ├ ○ /projects (592 ms)                             2.47 kB        46.5 kB
11:10:31 PM: ├ ● /real-estate (3204 ms)                         3.27 kB        47.3 kB
11:10:31 PM: ├ ● /real-estate/[...slug] (2329 ms)               536 B          50.3 kB
11:10:31 PM: ├   ├ /real-estate/haus-am-see-essen (1309 ms)
11:10:31 PM: ├   └ /real-estate/haus-am-see-dortmund (1020 ms)
11:10:31 PM: ├ ● /real-estate/page/[page] (3098 ms)             3.24 kB        47.3 kB
11:10:31 PM: ├   └ /real-estate/page/1 (3098 ms)
11:10:31 PM: ├ ● /tags (3194 ms)                                1.86 kB        42.5 kB
11:10:31 PM: └ ● /tags/[tag] (5699 ms)                          3.25 kB        47.3 kB
11:10:31 PM:     ├ /tags/haus (2890 ms)
11:10:31 PM:     └ /tags/see (2809 ms)
11:10:31 PM: + First Load JS shared by all                      40.6 kB
11:10:31 PM:   ├ chunks/main.e5a452.js                          30.7 kB
11:10:31 PM:   ├ chunks/pages/_app.e0d974.js                    9.04 kB
11:10:31 PM:   ├ chunks/webpack.ddd010.js                       822 B
11:10:31 PM:   └ css/0d5aca6fb15257a916bf.css                   6.41 kB
11:10:31 PM: λ  (Lambda)  server-side renders at runtime (uses getInitialProps or getServerSideProps)
11:10:31 PM: ○  (Static)  automatically rendered as static HTML (uses no initial props)
11:10:31 PM: ●  (SSG)     automatically generated as static HTML + JSON (uses getStaticProps)
11:10:31 PM:    (ISR)     incremental static regeneration (uses revalidate in getStaticProps)
11:10:31 PM: info  - Loaded env from /opt/build/repo/.env
11:10:31 PM: info  - Using webpack 5. Reason: Enabled by default https://nextjs.org/docs/messages/webpack5
11:10:32 PM: warn  - You have enabled experimental feature(s).
11:10:32 PM: warn  - Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use them at your own risk.
11:10:32 PM: info  - using build directory: /opt/build/repo/.next
11:10:32 PM: info  - Copying "static build" directory
11:10:32 PM: info  - No "exportPathMap" found in "next.config.js". Generating map from "./pages"
11:10:32 PM: Error: Image Optimization using Next.js' default loader is not compatible with `next export`.  Possible solutions:
11:10:32 PM:     - Use `next start` to run a server, which includes the Image Optimization API.
11:10:32 PM:     - Use any provider which supports Image Optimization (like Vercel).
11:10:32 PM:     - Configure a third-party loader in `next.config.js`.
11:10:32 PM:     - Use the `loader` prop for `next/image`.
11:10:32 PM:   Read more: https://nextjs.org/docs/messages/export-image-api
11:10:32 PM:     at /opt/build/repo/node_modules/next/dist/export/index.js:257:23
11:10:32 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/telemetry/trace/trace.js:60:20)
11:10:32 PM: ​
11:10:32 PM: ────────────────────────────────────────────────────────────────
11:10:32 PM:   "build.command" failed                                        
11:10:32 PM: ────────────────────────────────────────────────────────────────
11:10:32 PM: ​
11:10:32 PM:   Error message
11:10:32 PM:   Command failed with exit code 1: next build && next export
11:10:32 PM: ​
11:10:32 PM:   Error location
11:10:32 PM:   In build.command from netlify.toml:
11:10:32 PM:   next build && next export
11:10:32 PM: ​
11:10:32 PM:   Resolved config
11:10:32 PM:   build:
11:10:32 PM:     command: next build && next export
11:10:32 PM:     commandOrigin: config
11:10:32 PM:     publish: /opt/build/repo/out
11:10:32 PM:     publishOrigin: config
11:10:32 PM:   plugins:
11:10:32 PM:     - inputs: {}
11:10:32 PM:       origin: ui
11:10:32 PM:       package: '@netlify/plugin-nextjs'
11:10:32 PM: Caching artifacts
11:10:32 PM: Started saving node modules
11:10:32 PM: Finished saving node modules
11:10:32 PM: Started saving build plugins
11:10:32 PM: Finished saving build plugins
11:10:32 PM: Started saving pip cache
11:10:32 PM: Finished saving pip cache
11:10:32 PM: Started saving emacs cask dependencies
11:10:32 PM: Finished saving emacs cask dependencies
11:10:32 PM: Started saving maven dependencies
11:10:32 PM: Finished saving maven dependencies
11:10:32 PM: Started saving boot dependencies
11:10:32 PM: Finished saving boot dependencies
11:10:32 PM: Started saving rust rustup cache
11:10:32 PM: Finished saving rust rustup cache
11:10:32 PM: Started saving go dependencies
11:10:32 PM: Finished saving go dependencies
11:10:35 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:10:35 PM: Creating deploy upload records
11:10:35 PM: Failing build: Failed to build site
11:10:35 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2
11:10:35 PM: Finished processing build request in 1m58.66229937s

Hi @utdev

It is because you are using Next/Image and are exporting Next.js as a static site. The error provides solutions for you.