Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Vercel - VERCEL_URL showing development URL instead of production URL?

Tags:

next.js

vercel

Deployed my application to Vercel. Filled in all the required ENV variables including the VERCEL_URL which equal to the production URL of my application. But on console log, it keeps showing the wrong URL and returns the development URL instead.

Trying to debug this for hours but it's confusing. ENV variables from the Vercel settings are correct.

Any tips?

like image 571
Galanthus Avatar asked Feb 01 '26 19:02

Galanthus


1 Answers

You shouldn't try to override VERCEL_ env vars as they will be set by the Vercel CI and take precedence over yours.

Instead, use something like:

export function getBaseUrl() {
  return process.env.VERCEL_ENV === "production"
    ? `https://www.my-custom-domain.com`
    : process.env.VERCEL_URL
    ? `https://${process.env.VERCEL_URL}`
    : `http://localhost:3000`;
}

This will give you access to the base URL during building:

  • locally in development mode: localhost
  • locally built: localhost
  • deployed in preview: the dynamic Vercel deployment URL
  • deployed into production: your hard-coded custom domain
like image 114
Dejan Avatar answered Feb 04 '26 15:02

Dejan



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!