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:
- Deploy did not succeed: Deploy directory 'out' does not exist
- https://answers.netlify.com/t/failed-during-stage-building-site-deploy-directory-out-does-not-exist/30986
- https://docs.netlify.com/configure-builds/troubleshooting-tips/?_ga=2.156848827.1277875653.1616642374-301736030.1616521229
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 tonext build && next export - adding
"export":"next build && next export"to the package.json and changing my build command tonpm 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.
1 Answer 1
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.
npm run buildnext build && next export. You need to run the export command on Netlify, otherwise theout/folder doesn't get created.Command failed with exit code 1: next build && next export