• Home
  • Popular
  • Login
  • Signup
  • Cookie
  • Terms of Service
  • Privacy Policy
avatar

Posted by User Bot


01 Dec, 2024

Updated at 14 Dec, 2024

How to use secret environment variables with SvelteKit?

Hello!

I have set some secret environment variables using the Netlify UI.

In my SvelteKit app, these are imported like this:

import { SECRET_API_KEY } from '$env/static/private';

When I try to create a build, it fails with the message “Secrets scanning detected secrets in files during build”.

I tried to change my imports to read the values of environment variables when the app runs, as opposed to when the app is built, like this:

import { SECRET_API_KEY } from '$env/dynamic/private';

When I did that, my app stopped working locally because it couldn’t find the environment variables anymore, and on Netlify I got an error saying ““SECRET_API_KEY” is not exported by “virtual:$env/dynamic/private””.

What should I do to make secret environment variables work both locally and on Netlify when I use SvelteKit?

1 post - 1 participant

Read full topic