500 Error on Vercel but Not in Localhost for /api/user/create

Hey everyone :waving_hand:,

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:

  • :no_entry: 500 Internal Server Error (delayed ~1.8 seconds)
  • We’ve already:
    • :white_check_mark: Whitelisted 0.0.0.0/0 in MongoDB Atlas
    • :white_check_mark: Verified MONGODB_URI is correct in Vercel env vars
    • :white_check_mark: Logged process.env.MONGODB_URI in the route and confirmed it loads
    • :white_check_mark: Route connects successfully locally and returns 200 every time
    • :white_check_mark: Used console.log() and console.time() to confirm that the error occurs after reaching MongoDB in production

We’re using:

  • mongoose for DB connection (lib/mongodb.ts)
  • bcryptjs for 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!

Never mind just a friendly reminder its okay to triple check your API strings

Sometimes that is the way. :laughing:

Thank you for coming back with what the issue was!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.