-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Environment
System:
OS: macOS 14.2.1
CPU: (8) arm64 Apple M1
Memory: 443.92 MB / 16.00 GB
Shell: 5.9 - /bin/zsh
Binaries:
Node: 21.5.0 - /usr/local/bin/node
npm: 10.2.4 - /usr/local/bin/npm
pnpm: 8.10.5 - ~/Library/pnpm/pnpm
Browsers:
Chrome: 120.0.6099.109
Safari: 17.2.1
npmPackages:
@auth/sveltekit: ^0.5.0 => 0.5.0
@sveltejs/kit: ^2.0.0
@Vite: ^5.0.3
@typescript: ^5.0.0
Reproduction URL
https://github.com/ubemacapuno/authjs-sveltekit2-demo.git
Describe the issue
Hey all, I'm using @auth/sveltekit with the newly-released SvelteKit 2.0. I noticed that my dev environment runs fine, but when I try to build, I run into an error regarding environment variables.
There is a section in the SvelteKit 2.0 migration docs for "Dynamic environment variables cannot be used during prerendering", where it is mentioned, "...dynamic environment variables can no longer be read during prerendering in SvelteKit 2 — you should use the static modules instead." I believe this is why I am running into trouble when running the build script.
Using SvelteKit 2.0 and @auth/sveltekit and building the project locally, I receive this error in my terminal:
Error: Cannot read values from $env/dynamic/private while prerendering (attempted to read env.AUTH_SECRET). Use $env/static/private instead
Any insight on a fix would be greatly appreciated, because I'm getting stuck just going off of the docs. Thank you!
How to reproduce
After starting a SvelteKit 2.0 project with @auth/sveltekit and setting up hooks.server.ts and environment variables per the docs, I run into an error when running npm run build:
You can checkout my demo, set .env for GITHUB_ID, GITHUB_SECRET, and AUTH_SECRET and run npm run build to see the error, or recreate yourself:
- Create a new SvelteKit project (currently version 2.0):
npm create svelte@latest my-appand also install @auth/sveltekit withnpm install @auth/sveltekit - Make sure dependencies are all installed with
npm install - Per the @auth.sveltekit docs, setup the src/hooks.server.ts file.
- Make sure to set your environmental variables per the docs (
GITHUB_ID,GITHUB_SECRET, andAUTH_SECRET) - Run
npm run build - See in your terminal for error:
Error: Cannot read values from $env/dynamic/private while prerendering (attempted to read env.AUTH_SECRET). Use $env/static/private instead
Expected behavior
Expect a build without the following error:
Cannot read values from $env/dynamic/private while prerendering (attempted to read env.AUTH_SECRET). Use $env/static/private instead