Unexpected end of JSON input error

Created: 2024-11-18
Updated: 2024-11-29
2 min read

Vercel supports Node.js 22

Starting 2024-11-22, Vercel supports Node.js 22. Switching to Node.js 22 locally and on Vercel caused no issues. Click here for the changelog

The support of newer Node.js versions is dependent on AWS Lambda runtime support. Click here for more details

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
1# Remove node_modules folder, which contains all the installed dependencies 2rm -rf node_modules 3# Remove .next folder, which contains all the built files 4rm -rf .next 5# Prune the npm store, which contains all the cached npm packages 6pnpm 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, Vercel only supports Node.js versions 20.x, 18.x, and 16.x. 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.