Hey everyone ๐,
Weโre building a Next.js app and our /api/user/create route works perfectly in local dev โ it creates a MongoDB user, hashes the password with bcryptjs, and returns 200.
But on Vercel, the same route gives us:
- โ
500 Internal Server Error(delayed ~1.8 seconds) - Weโve already:
- โ
Whitelisted
0.0.0.0/0in MongoDB Atlas - โ
Verified
MONGODB_URIis correct in Vercel env vars - โ
Logged
process.env.MONGODB_URIin the route and confirmed it loads - โ Route connects successfully locally and returns 200 every time
- โ
Used
console.log()andconsole.time()to confirm that the error occurs after reaching MongoDB in production
- โ
Whitelisted
We're using:
mongoosefor DB connection (lib/mongodb.ts)bcryptjsfor hashing- App Router with
app/api/user/create/route.ts
Weโre even returning the error stack trace in production and still just get a generic failure. Logs on Vercel donโt show the error clearly due to retention limit.
Any ideas why Vercel would fail where localhost succeeds?
Thanks in advance โ we're stumped and happy to post snippets if needed!