Nextjs build Unexpected end of JSON input

I got this crazy error in NextJS 15

npm run build --verbose
npm verbose cli /opt/homebrew/Cellar/node/23.2.0/bin/node /opt/homebrew/bin/npm
npm info using npm@11.1.0
npm info using node@v23.2.0
npm verbose title npm run build
npm verbose argv "run" "build" "--loglevel" "verbose"
npm verbose logfile logs-max:10 dir:/Users/g/.npm/_logs/2025-05-26T14_04_24_112Z-
npm verbose logfile /Users/g/.npm/_logs/2025-05-26T14_04_24_112Z-debug-0.log

> playchoo@0.0.0 build
> next build

   ▲ Next.js 15.3.2
   - Environments: .env

   Creating an optimized production build ...
Failed to compile.

./node_modules/next/dist/build/webpack/loaders/next-app-loader/index.js?page=%2Fapi%2Faccounts%2Fsearch%2Froute&name=app%2Fapi%2Faccounts%2Fsearch%2Froute&pagePath=private-next-app-dir%2Fapi%2Faccounts%2Fsearch%2Froute.ts&appDir=%2FVolumes%2FAppleFS%2FkDrive%2FDocuments%2Fworkspace%2Fpadelry-nextjs%2Fsrc%2Fapp&appPaths=%2Fapi%2Faccounts%2Fsearch%2Froute&pageExtensions=tsx&pageExtensions=ts&pageExtensions=jsx&pageExtensions=js&basePath=&assetPrefix=&nextConfigOutput=&nextConfigExperimentalUseEarlyImport=&preferredRegion=&middlewareConfig=e30%3D! + 1 modules
Unexpected end of JSON input


> Build failed because of webpack errors
npm verbose cwd /Volumes/AppleFS/kDrive/Documents/workspace/padelry-nextjs
npm verbose os Darwin 24.4.0
npm verbose node v23.2.0
npm verbose npm  v11.1.0
npm verbose exit 1
npm verbose code 1

Fixing "Unexpected end of JSON input" in Next.js 13,14 or 15 with Node.js 23.2.0

Running into the "Unexpected end of JSON input" error during a Next.js build with Node.js version 23.2.0? This issue often stems from compatibility problems. Here's a quick fix: switch to Node.js version 22 using nvm.

The Solution

Install Node.js 22 with nvm:

nvm install 22

Switch to Node.js 22:

nvm use 22

Rebuild Your Project:

npm run build

Why It Works

Node.js 23.2.0 may conflict with Next.js build tools like Webpack. Switching to version 22 ensures compatibility and resolves the error.

Still Stuck?

Clear the .next cache and node_modules, then reinstall dependencies. Update Next.js to the latest version.

This simple switch using nvm should get your Next.js build running smoothly again!