-
-
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
Environment variables on process.env
sometimes not available in hooks.js in local dev
#3030
Comments
Thanks for workaround. Confirm this bug with |
I am also facing the same issue. Your walkaround works perfectly, but only on Development. On production, |
Same issue here |
SvelteKit/Vite had never load Note: We have a brief documentation about it. |
Hey @bluwy thanks for the confirmation. I haven't run into issues using It's worth noting this is only affecting my dev environment, and production (on Vercel, using the Vercel adapter) is okay. I guess the confusion that motivated me filing this issue is due to how we're able to use |
this solution works for DEV env. I hope it works for production env too:
|
You don't need a plugin, either of these will work: NODE_OPTIONS='-r dotenv/config' npm run dev npx --node-options='-r dotenv/config' svelte-kit dev |
Going to close this in favour of #4296, which covers this along with various other aspects of env vars |
Describe the bug
I'm looking to use the
handle
hook to add authentication and authorization middleware to my API routes, however the variables needed to verify user JWT's are sometimes not available when the hook runs, but only in local development. In my experience these variables were available just once after upgrading dependencies to use Vite 2.7.1, however on subsequent attempts/restarts of the dev server these variables were no longer available and thus all API attempts would be unauthorized. I've attempted to remove the.svelte-kit
directory, node_modules, lockfile, and reinstall to no avail.It is important to note this is only experienced during local development with
svelte-kit dev
, and may actually be a Vite-related issue (given the Svelte-Kit scope I decided to file here first to see what y'all's thoughts are).This can be mitigated by adding a small Vite plugin to load secrets with
dotenv
And for reference, the
hooks.js
file:Reproduction
npm init svelte@next my-app
.env
file in the project root, add an environment variablesrc/hooks.js
:svelte-kit dev
and observe errorLogs
No response
System Info
dependencies are installed with
pnpm
, Vite version is 2.7.1Severity
serious, but I can work around it
Additional Information
No response
The text was updated successfully, but these errors were encountered: