Skip to content
Node.js and Python3 min read

Next.js build fails on hosting: Build error occurred

> Build error occurred

Short answer

`next build` on cPanel hosting usually fails because the build needs more memory and CPU than the account's limits allow, so it ends with `Killed`, or because Node.js is older than Next.js requires, or because of a TypeScript error or an import path with the wrong letter case. The reliable fix is to build on your computer or in GitHub Actions, upload only the output, and use `output: "standalone"` so the server needs as little as possible.

ArabyHost teamLast updated: ShareWhatsAppXLinkedIn
Contents
  1. The most likely causes, in order
  2. How to confirm it’s fixed
  3. Prevention
  4. On ArabyHost

When a build fails you see a line such as > Build error occurred, Failed to compile, or a single word, Killed, and then everything stops. The line just before the last message tells you which of the causes below is yours. If an AI tool wrote the project, most of these don’t require touching the code at all.

The most likely causes, in order

1. The account’s memory or process limit

What you see: Killed, JavaScript heap out of memory, or spawn EAGAIN. next build starts several worker processes and uses a lot of memory, and on shared hosting each account has its own memory and process limits (LVE), so the system ends the build.

Check: open Resource Usage in cPanel and look for memory or process faults at the time of the build.

Fix: don’t build on the server. Build on your computer or in GitHub Actions and turn on standalone output in next.config.mjs:

const nextConfig = { output: "standalone" };
export default nextConfig;

After npm run build, prepare the folder you’ll upload:

cp -r public .next/standalone/
cp -r .next/static .next/standalone/.next/

Upload the contents of .next/standalone to the app folder (outside public_html), and in Setup Node.js App set Application startup file to server.js. That folder already contains the runtime packages, so don’t click Run NPM Install. Build on Linux (for example ubuntu-latest in GitHub Actions) if the project uses compiled packages such as sharp.

2. Node.js is too old

What you see: You are using Node.js 18.x. For Next.js, Node.js version ">=20.9.0" is required.

Fix: in Setup Node.js App pick version 20 or 24 for the app and restart it. Check over SSH inside the app’s environment with node -v.

3. TypeScript errors

What you see: Type error: with a file name and line number. next dev tolerates these; the production build stops on them.

Fix: run npm run build locally before every upload and fix the reported error, or give the full error text to your AI tool. Only skip type checking temporarily, knowing the risk.

4. Import paths with the wrong letter case

What you see: Module not found: Can't resolve './components/Header' although it works on your machine. Linux file systems are case sensitive.

Fix: make the path in import match the real file name exactly, then rebuild.

5. Environment variables missing at build time

What you see: Error occurred prerendering page or a database connection error during the build. Variables starting with NEXT_PUBLIC_ are baked into the files at build time, and static pages may query the database while building.

Fix: provide the environment variables where you build (.env.production locally or Secrets in GitHub Actions), and add runtime secrets in the Environment variables section of the app’s page.

How to confirm it’s fixed

A successful build prints the route table and ends without Build error occurred, leaving a .next folder (or out/ for a static export). After uploading, click Restart on the app’s page and open the site. If you then get a 503, the problem is in starting the app, not building it: see Node.js app returns 503.

Prevention

  • Make the build a CI step, not something the production server does.
  • Use the same Node version locally and on the server, and record it under engines in package.json.
  • Run npm run build before every upload, not only npm run dev.

On ArabyHost

On ArabyHost AI/Developer plans, Next.js with SSR runs through Setup Node.js App (the CloudLinux selector with Phusion Passenger) on Node.js 20 or 24, and each account has its own resource limits, which is why we recommend building elsewhere. A static export (output: "export") runs on any plan. The Next.js deploy guide covers both routes, and Araby AI in the panel reads the error log and explains the fix. See AI/Developer hosting for what the plans include.

FAQ

Can I run next build on shared hosting at all?

On small projects it may work, but a build uses a lot of memory for minutes, and the account's limits can stop it any time. The dependable approach is to build on your machine or in CI, upload the output, and only run the server on the hosting.

What does output: standalone do?

Next.js writes a `.next/standalone` folder containing `server.js` and only the packages needed at runtime, so you don't have to install every dependency on the server. Copy `public` and `.next/static` into it and use `server.js` as the startup file.

Why does the build pass on my laptop but fail on the server with Module not found?

Linux treats upper and lower case in file names as different, while Windows and macOS don't by default. Importing `./components/Header` for a file named `header.tsx` works locally and fails on the server.

Do I need Node.js for a static Next.js site?

No. With `output: "export"` the build is HTML, CSS and JavaScript in `out/`, which you upload to public_html on any plan, as long as the site uses no SSR or API routes.

Useful? Share it with someone who needs it:WhatsAppXLinkedIn

Read next

Ready to put your idea online?

Fast, isolated hosting, support that understands you, and an AI assistant that fixes problems with you.