Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploy did not succeed: Deploy directory 'out' does not exist

When deploying an app created with Next.js to netlify, the following error occurs and the deployment fails.

────────────────────────────────────────────────────────────────
  6. Deploy site                                                
────────────────────────────────────────────────────────────────
​
​
────────────────────────────────────────────────────────────────
  Configuration error                                           
────────────────────────────────────────────────────────────────
​
  Error message
  Deploy did not succeed: Deploy directory 'out' does not exist
​
  Resolved config
  build:
    command: yarn build
    commandOrigin: config
    publish: /opt/build/repo/out
  plugins:
    - inputs: {}
      origin: config
      package: '@netlify/plugin-nextjs'
    - inputs: {}
      origin: config
      package: netlify-plugin-cache-nextjs
Caching artifacts
Started saving node modules
Finished saving node modules
Started saving build plugins
Finished saving build plugins
Started saving yarn cache
Finished saving yarn cache
Started saving pip cache
Finished saving pip cache
Started saving emacs cask dependencies
Finished saving emacs cask dependencies
Started saving maven dependencies
Finished saving maven dependencies
Started saving boot dependencies
Finished saving boot dependencies
Started saving rust rustup cache
Finished saving rust rustup cache
Started saving go dependencies
Finished saving go dependencies
Build failed due to a user error: Build script returned non-zero exit code: 2
Failing build: Failed to build site
Failed during stage 'building site': Build script returned non-zero exit code: 2
Finished processing build request in 1m25.310488139s

The various files and settings are shown below.

netlify.toml

[build]
  command = "yarn build"
  publish = "out"

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

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

package.json

...
"scripts": {
  "dev": "next",
  "build": "next build",
  "start": "next start",
  "export": "next export"
},
...

Netlify | Build settings
congif

The various settings are based on the following pages.

  • Failed during stage 'building site': Deploy directory 'out' does not exist - Support - Netlify Community
  • Next.js on Netlify | Netlify Docs

If you know how to solve this problem, please let me know.
I'm open to any ideas.

like image 938
Jay White Avatar asked Feb 24 '21 15:02

Jay White


1 Answers

Also you may need to add target: 'serverless' to your next.config.js file.

like image 198
zomars Avatar answered Oct 12 '22 22:10

zomars