I am creating a SvelteKit project, and have declared environment variables that I need to access.
.env
ENV_VAR_NAME='random123'
src/hooks.server.js
import { ENV_VAR_NAME } from '$env/static/private';
//rest of my code here
The above code works in development. However, when I deploy it to Vercel, I get the following error. The issue occurs even when I have declared the environment variable in Vercel.
RollupError: "ENV_VAR_NAME" is not exported by "$env/static/private", imported by "src/hooks.server.js".
If the variable is set dynamically in Vercel and thus not injected into the code at build time, you have to use $env/dynamic/private
instead.
This module provides access to runtime environment variables, as defined by the platform you're running on.