Could not find a production build in the '.next' directory: how to fix it in Next.js
Could not find a production build in the '.next' directory means next start found no BUILD_ID file in the build folder: next build did not run, wrote its output somewhere else (distDir, another working directory in a monorepo), or the folder was lost between build and start, as in a Docker stage that does not copy it. Run next build before next start in the same folder. A static export (output: 'export') has no server to start: serve the out folder instead.
By Livops team, the people who build and run LivopsUpdated
What next start prints when there is no build to start[2]:
Error: Could not find a production build in the '.next' directory. Try building your app with 'next build' before starting the production server. https://nextjs.org/docs/messages/production-start-no-build-id
next start, or a custom server in production mode, needs a production build[1], and it did not find one. This page explains what it looks for, lists the five usual reasons it is missing on a server, and shows how to check before you deploy. For the whole setup of a Next.js app in production, see Next.js hosting.
What next start looks for
When the production server boots, it reads a file named BUILD_ID from the build folder[2][3]. If that file does not exist, it throws this error, with the folder it looked in between the quotes[2]. Next.js’s own fixes are two lines: run next build to create a production build before booting the production server, or run next dev if you meant the development server[1].
The CLI says the same: next start starts the application in production mode, and the application should be compiled with next build first[4]. The usual package.json[5]:
{
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start"
}
}
Then npm run build builds the app and npm run start starts the Node.js server[5]. Both, in that order, in the same folder.
Causes, most common first
1. next start ran without next build
The deploy runs only npm start, the build step is missing or was skipped, or the build failed and the start ran anyway. Add next build as the build step, and make a failed build stop the deploy.
A .next folder from next dev does not count: development builds output to .next/dev instead of .next[4].
2. The build went to another folder: distDir
distDir in next.config.js replaces .next with a folder of your choice; with distDir: 'build', next build writes to build[6]. next start reads the same config, and the error names the folder it actually searched[2]. If the name between the quotes is not where your build went, the build and the start are not reading the same next.config.js, or one of them ran in another folder (cause 3).
distDir is resolved relative to the folder that holds next.config.js[6]. Next.js takes ownership of that folder and will sometimes delete its contents[6], so do not point it at a folder that holds anything else.
3. The wrong working directory, often in a monorepo
next build and next start both take an optional directory and use the current directory when none is given[4]. In a monorepo, a build run inside apps/web and a start run from the repository root look at two different folders. Run both in the app’s folder, or pass it to both:
next build apps/web
next start apps/web
4. The build folder was lost between build and start
The build succeeded, but the start runs somewhere that does not have its output: a Docker stage that copies only the source and node_modules, a .dockerignore that leaves .next out, or a CI job that builds in one job and starts in another without passing the folder along.
Next.js’s own Docker example does not run next start at all. It builds with output: 'standalone', copies .next/standalone, .next/static and public from the build stage into the final stage, and starts node server.js[8]:
COPY --from=builder --chown=node:node /app/public ./public
COPY --from=builder --chown=node:node /app/.next/standalone ./
COPY --from=builder --chown=node:node /app/.next/static ./.next/static
CMD ["node", "server.js"]
output: 'standalone' creates .next/standalone, which can be deployed on its own without installing node_modules, together with a minimal server.js to use instead of next start[7]. That server does not copy public or .next/static by default; copy them in, and it serves them[7]:
cp -r public .next/standalone/ && cp -r .next/static .next/standalone/.next/
node .next/standalone/server.js
next start with standalone output only warns and points you to node .next/standalone/server.js[10]. If you keep next start instead, copy the whole build folder to the final stage, along with node_modules, package.json and public.
5. A static export: there is no server to start
With output: 'export' in next.config.js, next build writes the app as HTML, CSS and JS into an out folder[9], and the result can be hosted on any web server that serves static files[9]. There is nothing for next start to run, and it refuses with a different message[10]:
"next start" does not work with "output: export" configuration. Use "npx serve@latest out" instead.
Serve the out folder as a static site. If you need features that require a server, such as cookies, rewrites, redirects, Server Actions or Image Optimization with the default loader, a static export does not support them[9]: remove output: 'export' and deploy the app as a Node.js server with next build and next start.
How to confirm the fix locally
Build and start the way the server will, from a clean folder:
rm -rf .next
npm run build
ls .next/BUILD_ID
npm run start
If ls finds .next/BUILD_ID (or BUILD_ID in your distDir), next start has what it needs. For a Docker image that runs next start, run the same ls inside the final image: docker run --rm --entrypoint ls your-image .next. next start listens on port 3000 by default, or on the PORT variable[4].
On Livops
- Next.js is detected. Livops reads your repository, detects Next.js and fills in the install, build and start commands. You can change them in the cabinet or in a
livops.jsonfile. - The build runs on every deploy. Every
git pushto the connected branch starts a new deploy, and Livops builds the app before it starts it. If the build fails, the log shows why and the old version keeps running. - Do not build in the start command. While an app runs, its code is read-only, so a start command that runs
next buildcannot write.next. Keep the build in the build step. A.nextfolder you upload is not used either: uploading a folder drops.next,node_modulesand the like. - The start command is set once. In
livops.json,buildis applied on every deploy, butstartonly when the project is created. To change the start command later, use Settings → Start; see No start command. - Server or static. A Next.js app that renders pages on the server is deployed as an Application, not a static site; deployed as a site, it ends with
ssr_output, and the fix is to make it an Application. A static export is a static site, which is free on Livops. If the build output folder is not found (no_output), set it in Settings → Output. See No site found. - Monorepos and Dockerfiles. For a monorepo, give the folder the project lives in (for example
apps/web) when you connect the repository. If the repository has aDockerfile, it is used, and what its final stage copies is up to you (cause 4). - Listen on
PORT. An Application must listen on the port in thePORTvariable;next startreads it.
If the build itself fails, see JavaScript heap out of memory in next build or Module not found: Can’t resolve. If it starts but nothing answers, see App not listening on the port.
Questions
What exactly is next start looking for?
A file named BUILD_ID inside the build folder, which is .next unless distDir says otherwise. next build writes it. If the file is not there, next start stops with this error and names the folder it looked in.
I ran next dev. Why is there still no production build?
next dev is the development server, not a build. Development output even goes to .next/dev rather than .next, so it leaves no production build behind. Run next build, then next start.
Can I commit the .next folder instead of building on the server?
It is the output of next build, with build-time values such as NEXT_PUBLIC_ variables already inlined, so build where you deploy instead. Some deploy tools also drop .next from what you upload: Livops does when you upload a folder.
My build runs in a different folder than my start. What do I do?
Both next build and next start take a directory argument and use the current directory when it is missing. Run them in the same folder, the one with next.config.js, or pass the same folder to both, for example next build apps/web and next start apps/web.
Do I use next start with output standalone?
No. With output standalone, next start only warns and tells you to run node .next/standalone/server.js. That minimal server does not copy the public and .next/static folders by default, so copy them next to it.
My project uses output export. How do I start it?
You do not. A static export has no Next.js server: next build writes HTML, CSS and JS into the out folder, and next start refuses to run with output export. Serve the out folder with any static web server, or deploy it as a static site.
Sources
- Next.js Docs — Could not find a production build (nextjs.org). Checked .
- Next.js source — packages/next/src/server/next-server.ts (raw.githubusercontent.com). Checked .
- Next.js source — packages/next/src/shared/lib/constants.ts (raw.githubusercontent.com). Checked .
- Next.js Docs — next CLI (nextjs.org). Checked .
- Next.js Docs — Deploying (nextjs.org). Checked .
- Next.js Docs — distDir (nextjs.org). Checked .
- Next.js Docs — output (nextjs.org). Checked .
- Next.js example — examples/with-docker/Dockerfile (raw.githubusercontent.com). Checked .
- Next.js Docs — Static Exports (nextjs.org). Checked .
- Next.js source — packages/next/src/server/next.ts (raw.githubusercontent.com). Checked .
Put your project online today
Connect GitHub or drop a folder. No card is asked for.
Deploy your Next.js appRelated
- Next.js hosting without Vercel: the options comparedNext.js runs on any host that runs Node: next build, then next start, and every feature works, Server Actions and image optimization included. On Livops a repository with next in package.json runs as a server from a push for 39 credits a month (39,000 so'm), and a static export is free. Here is how Vercel, Render, Railway, Fly.io and a VPS compare.
- JavaScript heap out of memory during next build: how to fix itNode's JavaScript heap reached its limit while Next.js was building, and V8 stopped the process. Raise the heap limit with NODE_OPTIONS=--max-old-space-size, staying below the memory the build really has, and cut what the build holds in memory: source maps, type checking during the build, and heavy dependencies.
- Invalid src prop on next/image, hostname is not configured under images in your next.config.js: how to fix itInvalid src prop (https://…) on next/image, hostname "…" is not configured under images in your next.config.js means the image's address does not match any entry in images.remotePatterns. Add the host to remotePatterns with the right protocol, port and path, restart next dev and build again. images.domains is deprecated since Next.js 14. In production the same mismatch shows as a broken image and a 400 from /_next/image.
- Module not found: Can't resolve './components/Header' in webpack and Next.js: how to fix itModule not found: Can't resolve './components/Header' means the bundler followed an import and found no file or package there. The usual causes: the file name's case differs from the import (fine on macOS and Windows, fatal on a Linux build server), a wrong relative path or a missing extension, a package that is not in package.json, an @/ alias the bundler does not know, and, for Can't resolve 'fs', Node-only code pulled into the browser bundle.
- App not listening on $PORT: why the health check failed after deployThe platform started your app, tried the port it gave it, and nothing answered in time. Almost always the app listens on its own fixed port instead of the PORT variable, listens on localhost (127.0.0.1) instead of 0.0.0.0, or crashed or was still starting when the check gave up. Listen on 0.0.0.0 and the port in PORT, and it passes.
- Docker hosting: how to deploy a Docker container or a DockerfileTo host a container you need a host that builds or pulls the image, starts its CMD, sends traffic to the port it listens on and stops it with SIGTERM. On Livops a Dockerfile at the root of the repository is built on Livops's servers and runs for 39 credits a month (39,000 so'm); a public image from Docker Hub, GHCR or Quay runs without a build. Here is what a container needs, and how a VPS, Render, Railway, Fly.io, DigitalOcean and Heroku compare.
- useSearchParams() should be wrapped in a suspense boundary: how to fix it in Next.jsnext build prerenders the page, and the query string does not exist at build time, so a Client Component that calls useSearchParams() needs a <Suspense> boundary above it. Wrap the smallest component that reads the search params in <Suspense>, read searchParams in the server page instead, or make the route dynamic with connection(). next dev renders on demand, which is why it only fails in the build.