Stack
- Next.js 14.2.2
- EC2 (Mumbai, ap-south-1)
- Nginx reverse proxy
- Cloudflare CDN (recently added, but issue existed even before)
The Issue
After deploying to production, our Next.js app works perfectly in India, but US users (New York, Virginia/Boydton) are getting ChunkLoadError on almost every page load.
Example error:
ChunkLoadError: Loading chunk 704 failed.
GET https://xxxx.xxx/_next/static/chunks/704-xxx.js
Status: 404 (HTML response instead of JS)
Sometimes the endpoint even returns:
- 200 OK with 0 bytes
- Or a 404 even though the file exists on the server
Framer pages on the same domain load fine everywhere. Only the Next.js chunks are failing.
What I've already tried:
Nginx buffering changes
Added buffer settings to fix any truncation issue. No effect.
Full rebuild + restart
rm -rf .next && npm run build && restartWorks temporarily, then fails again for US users.
Verified files on the server
The chunk files exist in
.next/static/chunks/.Direct access to Node server
Fetching the same chunk from
localhost:3000works fine.Added Cloudflare CDN
Moved DNS to Cloudflare expecting caching to fix the issue - but the same problem is still happening.
Symptoms
- Indian users → no issues
- US users → consistent chunk failures
- 404 responses returning HTML instead of JS
- Sometimes 0-byte responses
- No firewall rules blocking traffic
- Route53 simple routing
- Only one EC2 instance (no race condition from multiple servers)
What I'm trying to understand
Why do chunk files return 404/empty responses only for certain regions?
If the files exist and Next.js serves them locally, why does Nginx return HTML/0-bytes?
Is this a caching or buffering issue with Nginx/Next.js?
Could Cloudflare be interfering even with "cache disabled"?
Is this related to Next.js static chunk invalidation?
What I need help with:
Has anyone seen region-specific ChunkLoadError with Next.js?
Is there something obvious I'm missing in the Nginx → Node setup?
Could this still be a deployment race condition even with one server?
Is there a reliable fix without moving fully to a CDN?
Any suggestions for how to debug Nginx returning HTML instead of JS?