ERR_INVALID_URL — Possibly linked to NextAuth v5

Upon deploying my NextJS application to Vercel, I get the following error log in preview/production:

TypeError: Invalid URL
    at new n (.next/server/chunks/9030.js:1:36758)
    at V (.next/server/chunks/6191.js:64:246284)
    at 36335 (.next/server/chunks/6191.js:64:246459)
    at t (.next/server/webpack-runtime.js:1:143)
    at 35168 (.next/server/chunks/9030.js:1:26444)
    at t (.next/server/webpack-runtime.js:1:143)
    at 81327 (.next/server/chunks/9030.js:1:44499)
    at Object.t [as require] (.next/server/webpack-runtime.js:1:143) {
  code: 'ERR_INVALID_URL',
  input: 'httpeace-lar73vvf5-pcnlabs.vercel.app',
  digest: '3781670148'
}

In my codebase, I make no explicit reference to VERCEL_URL, nor do I use “new URL” without adding “https://”. I suspect it might have something to do with NextAuth, but can’t confirm. I have tried setting the AUTH_URL env, and removing it, but in both cases the error happens. I have " Automatically expose System Environment Variables" on.

What could possibly be happening?

I managed to fix it by adding the NEXTAUTH_URL env in addition to the AUTH_URL. The NextAuth v5 documentation is wrong: There are still pieces of the latest beta release that reference NEXTAUTH_URL and use VERCEL_URL as fallback without correctly prepending it with “https://”.

Glad to hear it’s working now. You can share the feedback here: nextauthjs/next-auth · Discussions · GitHub

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