Search code examples
node.jsnpmnext.jsnetlify

NextJS on Netlify: Deploy did not succeed; Deploy directory 'out' does not exist


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.


Solution

  • 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.