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
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!