-
-
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
RollupError: "AUTH_SECRET" is not exported by "virtual:$env/static/private", imported by "src/hooks.server.ts" #11425
Comments
The only way now to be able to build will be to include all environment variables in Drone CI so that sveltekit 2 can import via $env/static/private during the build. Was this change in Sveltekit 2 really necessary? Would there be any other solution to work with private dynamic variables? |
Are you using prerendering? (Trying to understand if this would be fixable by relaxing the constraint to only error when env variables are accessed during prerendering) |
Hi @dummdidumm, This is my
and still have problems with importing Well, I'll have to downgrade to Sveltekit 1 until this is resolved. It will be a hassle to have to include all the environment variables to be able to build the application. Previously, if I needed to change the value of a variable, I would simply redeploy the application to my Kubernetes, which took seconds. Now I would have to do a new build to include a static variable, and it would take seconds to at least 10 minutes to do the entire process of building, creating the docker image and deploying the application to argo-cd. |
Ok so you're not using prerendering - in that case, it should be possible to keep using |
Thank you very much, @dummdidumm!! |
It seems to be still not working for me, using the same
During
|
Update to the latest version of 2.0 which should resolve the issue. It was fixed in the version 2.0.6 https://github.com/sveltejs/kit/releases/tag/%40sveltejs%2Fkit%402.0.6 |
I have just tried, |
Actually, if this helps, I am trying to import .env variables in API routes. |
Try run |
I am afraid this does not work either. OK, what I did is I created the fresh 'skeleton' project, JS + JSDoc:
I added a /src/routes/+layout.js with:
I added /src/routes/+server.js with:
Created also a
Next, issued
|
Doesn't work for me — neither with the new skeleton project nor with the old one updated to 2.4.3.
Please, help. Am I missing something? |
|
Found the solution and expectedly feel stupid, I guess I didn't read the documentation properly. Based on the error messages, it looks like it's the same issue both @janguardian and @PlkMarudny ran into. In Sveltekit, dynamic and static environment variables are accessed differently. Staticimport { API_KEY } from '$env/static/private';
console.log(API_KEY) Dynamicimport { env } from '$env/dynamic/private';
console.log(env.API_KEY) |
Check your .gitignore file,maybe .env in the ignore list |
Check your .gitignore file,maybe .env in the ignore list |
Describe the bug
9: import {
10: AUTH_SECRET,
^
11: KEYCLOAK_ID,
12: KEYCLOAK_SECRET,
error during build:
RollupError: "AUTH_SECRET" is not exported by "virtual:$env/static/private", imported by "src/hooks.server.ts".
at error (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/parseAst.js:337:30)
at Module.error (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:12738:16)
at Module.traceVariable (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:13175:29)
at ModuleScope.findVariable (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:11592:39)
at Identifier.bind (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:7179:40)
at Property.bind (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:4625:23)
at ObjectExpression.bind (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:4621:28)
at CallExpression.bind (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:4621:28)
at CallExpression.bind (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:8813:15)
at VariableDeclarator.bind (file:///drone/src/node_modules/vite/node_modules/rollup/dist/es/shared/node-entry.js:4625:23)
Reproduction
No response
Logs
No response
System Info
Severity
blocking all usage of SvelteKit
Additional Information
"Dynamic environment variables can no longer be read during prerendering in SvelteKit 2 — you should use the static modules instead."
Sveltekit 2 changed the way we use dynamic private environments like
import { env as privateEnv } from $env/dynamic/private
, so the recommendation is to use$env/static/private
.What should we do now in a CI to be able to build?
My Drone CI build does not have any environment variables or static .env in the repository. The environment variables on my system are passed in the k8s deployment only during execution.
The text was updated successfully, but these errors were encountered: