next export is gone: moving to output: 'export'
The "next export" command has been removed in favor of "output: export" in next.config.jsShort answer
Next.js 14 removed the next export command. Set output: 'export' in next.config.js and run next build; the static files land in the out folder. If the build then fails, a feature that needs a server is in use, such as cookies, rewrites or the default image loader.
Fix it fast
1Find out which cause you have
Look at your build script. If it still calls next export, that is the whole error.
grep -n "next export" package.json2Match what you see, then jump to its fix
- 1
The package.json script is next build && next exportThe build script still runs next exportFix - 2
Build passes, hosting says the publish directory is missingThe deploy still looks for the old output folderFix - 3
The build fails after output: 'export' was added, naming a route, cookies, redirects or imagesThe app uses something a static export cannot serveFix
- 1
What does the error look like?
The "next export" command has been removed in favor of "output: export" in next.config.js
Cause 1 of 3
The build script still runs next export
1Check
next export was deprecated in 13.3 and removed in 14.0. A deploy that still runs it fails after upgrading.
grep -n "export" package.json next.config.*2Fix
Turn on the static output in the config and delete the next export step. next build now writes the site to out.
// next.config.js
const nextConfig = {
output: 'export',
}
module.exports = nextConfig
// package.json
"build": "next build"3Verify
Build and look for the out folder.
npm run build
ls outConfirmed by nextjs.org
Cause 2 of 3
The deploy still looks for the old output folder
1Check
The static export is written to out by default, unless distDir is set.
grep -n "distDir" next.config.*2Fix
Point the host's publish directory at out, or set distDir to the folder name the host expects.
// next.config.js
const nextConfig = {
output: 'export',
distDir: 'dist', // only if the host needs dist
}
module.exports = nextConfig3Verify
Rebuild and list the folder.
ls distConfirmed by nextjs.org
Cause 3 of 3
The app uses something a static export cannot serve
1Check
Static export cannot use cookies, rewrites, redirects or headers in next.config, a proxy, Server Actions, ISR, dynamic routes without generateStaticParams, or the default image loader.
grep -rn "cookies()\|generateStaticParams\|redirects\|rewrites" app next.config.*2Fix
Remove or replace each one. For example, add generateStaticParams to dynamic routes, and define a custom image loader.
// app/blog/[id]/page.tsx
export async function generateStaticParams() {
return [{ id: '1' }, { id: '2' }]
}
// next.config.js
const nextConfig = {
output: 'export',
images: { loader: 'custom', loaderFile: './my-loader.ts' },
}3Verify
Run the build; it should finish without errors.
npm run buildConfirmed by nextjs.org
How do I stop it coming back?
- Decide early whether the project needs a server; static export closes that door.
- Run next build in CI so a removed feature shows up before a release.
- Use a host that can serve plain files, such as nginx with try_files, for the out folder.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Servers
A Next.js static export works by clicking links but gives 404 on refresh or deep links
The home page loads, but a direct link to /blog/post-1 returns 404
A static export writes one HTML file per route, such as about.html.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fixWeb apps
Firebase Auth says the API key is not valid
Firebase: Error (auth/api-key-not-valid.-please-pass-a-valid-api-key.)
The apiKey your app sends is either empty, wrong, or blocked.
4 causes, each with a fix