Framework environment variables not being injected in external builds

We build our production env via GitHub Actions.

Your docs mention that framework envs are injected into the build environment.

This used to work, but it doesn’t anymore. My build in a nutshell:


pnpm vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}

pnpm vercel build --target=production --token=${{ secrets.VERCEL_TOKEN }}

pnpm vercel deploy --prebuilt --target=production --token=${{ secrets.VERCEL_TOKEN }}

If I export the environment variables in the build step I don’t see any of the VERCEL_ environment variables mentioned in the docs.

Did something change recently?

Hi @leonardofaria,I think this would be the correct explanation here:

1 Like

When did this change happen? Investigating things on my side and the date would be relevant. Thank you

Hi @leonardofaria, I think it happened around v34. You can read more on this issue [cli] Removing VERCEL_ENV in vercel@34.2.0 is a breaking change · Issue #11633 · vercel/vercel · GitHub.

Found a related PR [cli] Don't pull system environment vars in dev by onsclom · Pull Request #11526 · vercel/vercel · GitHub from May 2024.

Can you share how your project depends on these variables? Maybe we can find a way around.

I have this constant to detect the domain of my app, supporting multiple envs (local, preview, production and an alternative production env) and I only noticed a problem last week:

export const BASE_URL =
  // eslint-disable-next-line no-nested-ternary -- .
  !process.env.NEXT_PUBLIC_VERCEL_ENV ||
  process.env.NEXT_PUBLIC_VERCEL_ENV === 'development'
    ? (process.env.NEXT_PUBLIC_URL ?? 'http://localhost:3000')
    : process.env.NEXT_PUBLIC_VERCEL_ENV === 'preview'
      ? `https://${process.env.NEXT_PUBLIC_VERCEL_URL}`
      : `https://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`;

I was able to fix this in my CI pipeline by setting the PUBLIC_URL:

export NEXT_PUBLIC_URL="https://app.domain.com"

This is no longer a problem, I was just curious because I’ve been using v44.7.3 for a while, so this timeline is weird, but not weird enough to keep investigating.

Thanks!