Vercel dev with system environment variables?

I’ve looked everywhere for an answer, but no avail, so I assume I might be doing something wrong.

The problem is simple, when I run vercel dev, process.env.VERCEL_GIT_REPO_OWNER is undefined (and other system env listed at System environment variables). This is a system environment variable. Available on deploy, but not locally. Do I need to hardcode it?

const REPO_OWNER = process.env.VERCEL_GIT_REPO_OWNER | "theuser";?

Furthermore, adding it to my .env.local also does not work, it appears ignored.

I am using Svelte, if that matters.

Please let me know what I’m understanding incorrectly!

Hi, XGD! Welcome to the Vercel Community. :smile:

Let me try and help out here!

The system environment variables you’re referring to, like VERCEL_GIT_REPO_OWNER, are automatically populated by Vercel during deployments . However, these variables are not automatically available when running vercel dev locally. This is because your local development environment doesn’t have the same context as a Vercel deployment. In summary:

  1. System environment variables are primarily intended for use in deployed environments
  2. When running vercel dev, you’re in a local development environment, which doesn’t have access to the same deployment context
  3. Adding these variables to .env.local doesn’t work because they are system-provided variables, not user-defined ones

You could solve this by using a fallback value in your code:

const REPO_OWNER = process.env.VERCEL_GIT_REPO_OWNER || "default_value";

Replace “default_value” with an appropriate default for your local development.

Or if you need specific values for local development, add them to your .env.local file:

VERCEL_GIT_REPO_OWNER=your_local_value

This will be used during vercel dev but won’t interfere with the system-provided value during actual Vercel deployments.

Let us know how you get on!