Unexpected JSON error

Happy 2025! Starting the year by sharing a solution that might save you some debugging time.

When running npm run build, I kept getting this error:

./node_modules/.... + 241 modules
Unexpected end of JSON input

This error showed up randomly across different projects for months. While most online discussions pointed to Next.js configuration issues, the real cause was using Node.js version 23.2 instead of the LTS version.

The fix:

nvm install --lts
nvm use --lts

Key Points

  • The error persists through project restarts and node_modules cleanup
  • Solutions focusing on Next.js configuration don’t fix it
  • Using Node.js LTS versions prevents this issue
  • Add an .nvmrc file to maintain consistent Node.js versions across teams

Prevention

  1. Use LTS versions for development and production
  2. Document Node.js version requirements
  3. Implement version control using .nvmrc files