Skip to main content

Unexpected end of JSON input error

Created: 2024-11-18
Updated: 2026-01-16
2 min read
Next.js
Node.js
Troubleshooting

Update: Vercel Node.js support has changed

Since this post was written, Vercel has updated its supported Node.js versions. As of November 2025, Vercel supports Node.js 20.x, 22.x, and 24.x (with 24.x as the default). Node.js 18.x and 16.x are no longer supported.

Check the Vercel Node.js documentation for current supported versions.

About a week ago, I started encountering build errors for this website that didn't make any sense. There were no changes in my code that matched the error message, and even reverting to previous commits didn't fix it. The only change I had made was updating all my dependencies to their latest versions, including upgrading to Next.js 15 and the latest React 19 RC. Currently, I'm even using canary versions of both. Despite this, pnpm dev --turbo worked perfectly, and everything built and deployed to Vercel without issues.

The error message was:

Text
Unexpected end of JSON input

Since it only happened locally, I assumed it was an issue with my environment and started some light cleaning:

Shell
# Remove node_modules folder, which contains all the installed dependencies
rm -rf node_modules
# Remove .next folder, which contains all the built files
rm -rf .next
# Prune the npm store, which contains all the cached npm packages
pnpm store prune

Even after this cleanup, the error persisted. After debugging for a while, I decided to let it go and hoped newer dependency versions would eventually resolve it.

The actual issue turned out to be much simpler—it was caused by the version of Node.js I was using. I prefer using the latest versions of software whenever possible, so months ago, I installed Node.js 23. It worked perfectly and was the latest stable version at the time. However, at the time of writing, Vercel only supported Node.js versions 20.x, 18.x, and 16.x (Vercel now supports 20.x, 22.x, and 24.x, with 24.x as the default). Interestingly, Next.js officially recommends Node.js 18.18 or later.

After switching to Node.js 20.x, the error disappeared, and everything built perfectly again.

Conclusion

This was an unexpected error, especially since it started suddenly and only locally. I'm not entirely sure what the root cause was, but it was definitely related to the Node.js 23 version and Next.js 15. The lesson learned here is to ensure the Node.js version on your local machine matches the one used on Vercel to rule out local causes. Also, avoid using Node.js versions not supported by Vercel.