Next.js Discord

Discord Forum

NEXT_PUBLIC_VERCEL_GIT_PULL_REQUEST_ID is empty in Preview

Answered
Bombay posted this in #help-forum
Open in Discord
Avatar
BombayOP
I'm trying to get the PR number during Preview, it returns empty string, it should return a number like the docs. I'm following this doc https://vercel.com/docs/concepts/projects/environment-variables/system-environment-variables

I confirm the Automatically expose System Environment Variables is checked in Settings.

Do I miss something? Appreciate any hint. 🙏
Answered by Bombay
OH it does not have PR ID on the first commit, it has to be the second commit.
View full answer

5 Replies

Avatar
BombayOP
I believe this is a bug. Other environment variables can show correctly:
- NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA
- NEXT_PUBLIC_VERCEL_GIT_COMMIT_AUTHOR_LOGIN
- NEXT_PUBLIC_VERCEL_GIT_COMMIT_AUTHOR_NAME

only the NEXT_PUBLIC_VERCEL_GIT_PULL_REQUEST_ID is incorrect
Image
the code to generate that server url:
  if (process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview') {
    return `https://server-myproject-pr-${process.env.NEXT_PUBLIC_VERCEL_GIT_PULL_REQUEST_ID}.up.railway.app`;
  }
Avatar
BombayOP
OH it does not have PR ID on the first commit, it has to be the second commit.
Answer
Avatar
Dwarf Crocodile
Hye @Bombay, I hit a similar problem. Do you happen to know if this is expected behavior, or a bug? I couldn't find anyone talking about it discord, reddit, or git...
Avatar
BombayOP
If I remember correctly, it’s the expected limitation from Vercel. I will try to find the doc.