-
-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"Cannot import $env/static/private.js into client-side code" when importing from a common functions file #5937
Comments
Tracking what functions call what - or what functions use what data - is a whole lot more work than just tracing the |
Perhaps the error could explain something to this effect? Something like:
|
Just in case someone gets the same issue as me…. There’s something odd in the auto import functionality in VSCode. Not sure how I triggered it but after receiving the same error and scratching my head for a while I found a new import at the top of my +page.svelte like this: import { _ } from ‘$env/static/private’; Like I said, no idea how I triggered it but I’ve had similar problems with VSCode, or some add-in creating unwanted imports over the last few months. |
Writing my observations here if anyone else is baffled by this issue. Naming matters, so don't name your function "serverFoo" in src/lib/serverFoo.ts if it's used also in client code. |
You saved my day, VSC is really annoying for that :D |
Got this today and the error seemed quite cryptic. My issue was related to how I was importing something.
|
This error is so annoying - it's just popped up out of nowhere, and I do not use any private variables. Why cant there be a clear stack trace that points one to the actual source of the error? This is such as bad DX.
What exactly am I supposed to get from this? |
VS Code (or a Svelte plugin?) will automatically add |
Describe the bug
This seems like a bug even though it could be the desired behaviour, but here I go:
Having a file
functions.js
including two functions:that supposedly fetches data from an API and requires access to
API_TOKEN` (a private and sensitive environment variable)multiply
that just takes 2 parameters and returns a number, without access to the env variableIt then fire this error:
If you comment the lines 2 and 8 of
src/routes/+pages.svelte
, then you have access to the information.This sort of makes sense but since
multiply
does not useAPI_TOKEN
, I don't see why we would have to separate functions into different files?A solution could be to isolate the functions that require access to private environment variables. Or am I missing something here?
Reproduction
https://stackblitz.com/edit/sveltejs-kit-template-default-s8msqa?file=src/routes/+page.svelte
Logs
System Info
Severity
serious, but I can work around it
Additional Information
Discord thread if that helps
https://discord.com/channels/457912077277855764/1009108558194950174
The text was updated successfully, but these errors were encountered: