2

I am currently developing a website and am hosting it on Netlify. Up until a recent change, It has been deploying with no issues. However, I pushed a change and suddenly, I get this error; Deploy did not succeed: Deploy directory 'out' does not exist. I know that there are many similar questions on here and other forums, but I have tried those solutions and their combinations with no success.
Sources that I viewed:

Here is the GitHub repository: https://github.com/henrikvtcodes/henrikvt.com-nextjs-old
Things I have tried:

  • adding "export":"next export" to the package.json and changing my build command to next build && next export
  • adding "export":"next build && next export" to the package.json and changing my build command to npm run export
  • The standard npm run build
  • Many more (can be seen in the commit history on GitHub)

All of these have either failed with the aforementioned error code or exit code 1.

I have no idea what to do. The standard npm run build command runs perfectly fine on my local system as well. Another piece of potentially useful information; I test-deployed the same repository on Vercel and that worked perfectly (somewhat as expected) but I'd rather use Netlify for multiple reasons.

asked Mar 25, 2021 at 15:52
5
  • What build command do you have in your deploy settings in Netlify? Commented Mar 25, 2021 at 21:24
  • Currently, it's set to npm run build Commented Mar 25, 2021 at 21:31
  • Try changing it to next build && next export. You need to run the export command on Netlify, otherwise the out/ folder doesn't get created. Commented Mar 25, 2021 at 21:32
  • the build failed with exit code:1. I am not sure if I have to import a module to handle it? Commented Mar 25, 2021 at 22:05
  • Command failed with exit code 1: next build && next export Commented Mar 26, 2021 at 0:42

1 Answer 1

4

When you have a next.config.js add target: serverless to it. The file will look something like this:

// next.config.js
module.exports = {
 future: {
 webpack5: true,
 },
 target: 'serverless'
}

What you can then do is add a netlify.toml file to the root of your project to tell Netlify it should run the build command like so:

// netlify.toml
[build]
 command = "yarn build"

This made my Next.js deploys to Netlify work.

answered Apr 22, 2021 at 15:40
Sign up to request clarification or add additional context in comments.

1 Comment

Adding target: 'serverless' worked for me, Thank you.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.