Home
Support Forums

Failed during stage 'building site': Deploy directory 'out' does not exist

Hi all,

I am trying to deploy a nextjs site to Netlify and following this guide: How to Deploy Next.js Sites to Netlify — 5-Minute Tutorial. I have seen similar posts but I haven’t found anyone else posting with this same exact error so I haven’t been able to solve it yet.

I have deployed a nextjs site to Netlify before and never experienced this. I’m getting this error: 4:14:50 PM: Failed during stage ‘building site’: Deploy directory ‘out’ does not exist!

These are my build settings: Screen Shot 2021-01-24 at 4.18.24 PM|690x149

Any help is much appreciated, thank you!

Have you tried building the website locally? If not then try that and check in what folder you’re getting the generated HTML files and then set that as the publish directory.

@evolfo having the same issue too. Did you find a solution?

I wasn’t able to figure it out, I switched to Vercel and have had no problems so far.

Hiya, sorry you are having trouble with your build.

This Support Guide contains a ton of useful debugging tips that can likely help you solve your problem :slight_smile:

We also recommend trying to search the forums with the build error you encountered - it’s likely your question was already asked by someone else!

If you are still having problems, please provide as much information as you can on what you have already tried, what your build settings are, your package.json, etc. Thanks!

@evolfo @gvocale The solution is simple. Either do what I have suggested in first reply or share your repo. Not continuing the thread will never get you to a solution sadly.

@hrishikesh @perry here is the repo. It’s just next.js default bootstrap app created via npx create-next-app. I then import that repo in Netlify, which tries to deploy the folder /out.

I suspect latest next.js version do not use /out anymore as build folder. I tried with /.next and didn’t seem to work either.

You seem to have missed the link.

Ops sorry, just edited my message.

Great. I’ll check it now.

It was a simple change. In your package.json add this script "export": "next build && next export". And then change your build command to npm run export.

1 Like

Nice! That worked! Thank you so much!

Adding the export script to package.json worked for me, but I saw a second site deployed fine without it.

Looking closer at the failed deploy I saw this:

3. onBuild command from @netlify/plugin-nextjs                

Your next.config.js must set the "target" property to one of: serverless, experimental-serverless-trace. Update the target property to allow this plugin to run.

It turns out the first failed site had a custom next.config.js that did not define target at all, and adding target: 'serverless' fixed it.

1 Like

Thank you for sharing this solution, @spro. :+1:

True, Vercel is absolutely seamless. We must also say they are the developers of Next.js, but deploying Next.js apps there is so, so smooth!

Thank you for sharing this, @gbrachetta!