SvelteKit 'Framework Env Vars' use VITE_ and are therefore not PUBLIC_

In Sveltekit, you can only use public environment variables in client-side code. This is envorced by the name of the env var, so it needs to start with PUBLIC_.

Vercel seems to acknowlege that this is the case, and has ‘Framework Environment Variables’ versions of the System Environment Variables to facilitate this. However, for some reason, with Sveltekit chosen, the prefix is not PUBLIC_ but VITE_. Unfortunately this doesn’t work and trying to import these names from $env/static/public gives a compile error (as expected).

Current:

As described here, when the Framework Preset is set to Sveltekit, the Vercel System Variables such as VERCEL_ENV are also exposed as VITE_VERCEL_ENV. However, in order to import them, Sveltekit requires that they be prefixed with PUBLIC_ instead of VITE_.

Expected:

With Sveltekit chosen as framework, I expected the variables to have PUBLIC_ prefix such as PUBLIC_VERCEL_ENV

Deployment URL or Custom Domain:
Environment (local, preview, production):
Project Framework: Sveltekit
Build Settings:
  Framework Preset:
  Build Command (if not default):
  Output Directory (if not default):
  Install Command (if not default):
Node/Runtime Version:
Package Manager:
Relevant Packages:

Hi @jeroenvdv. The VITE_ prefix is used for the original version of SvelteKit (v0), but recent versions work a bit differently. You can access deployment-specific environment variables from $env/static/private. An example of this is outlined in the SvelteKit docs: Vercel • Docs • SvelteKit

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