kit: RollupError: "AUTH_SECRET" is not exported by "virtual:$env/static/private", imported by "src/hooks.server.ts"
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
Need to install the following packages:
envinfo@7.11.0
Ok to proceed? (y) y
System:
OS: macOS 14.2
CPU: (10) arm64 Apple M2 Pro
Memory: 120.92 MB / 32.00 GB
Shell: 5.9 - /usr/local/bin/zsh
Binaries:
Node: 18.19.0 - ~/n/bin/node
Yarn: 4.0.2 - ~/n/bin/yarn
npm: 10.2.3 - ~/n/bin/npm
bun: 1.0.18 - ~/.bun/bin/bun
Browsers:
Chrome: 120.0.6099.129
Edge: 120.0.2210.89
Safari: 17.2
npmPackages:
@sveltejs/adapter-auto: ^3.0.1 => 3.0.1
@sveltejs/adapter-node: ^2.0.1 => 2.0.1
@sveltejs/kit: ^2.0.4 => 2.0.4
@sveltejs/vite-plugin-svelte: ^3.0.1 => 3.0.1
svelte: ^4.2.8 => 4.2.8
vite: ^5.0.10 => 5.0.10
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.
About this issue
- Original URL
- State: closed
- Created 6 months ago
- Comments: 15 (8 by maintainers)
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.
Static
Dynamic
I am afraid this does not work either. OK, what I did is I created the fresh ‘skeleton’ project, JS + JSDoc:
pnpm install
output:I added a /src/routes/+layout.js with:
I added /src/routes/+server.js with:
Created also a
.env
file with:Next, issued
pnpm run build
and the result was:Ok so you’re not using prerendering - in that case, it should be possible to keep using
$env/dynamic/..
and we need to fix it