-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Update 60-env-vars.md #4013
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
Update 60-env-vars.md #4013
Conversation
VITE doesn't use `process.` it's `import.meta`
|
|
This is code that, on the server side, isn't changed by Vite at all. It's just |
Whoops, I'm on the mobile app and I missed Rich's comment. Yes the |
Interesting. The FAQ is a bit confusing then... If I'm using an environment variable in a .js file, /* supabaseClient.js */
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = process.env.VITE_SUPABASE_URL;
const supabaseAnonKey = process.env.VITE_SUPABASE_ANON_KEY;
export const supabase = createClient(supabaseUrl, supabaseAnonKey); /* src/routes/auth/index.js */
<script>
import { supabase } from '$lib/supabaseClient';
let loading = false;
let email;
console.log(supabase);
</script> But if I change |
Yeah I think the above paragraph "Vite uses dotenv..." could have mention the
You should be using |
Ohhh I see! That makes sense. Appreciate the help.
…On Feb 19, 2022, 20:47 -0700, Bjorn Lu ***@***.***>, wrote:
Yeah I think the above paragraph "Vite uses dotenv..." could have mention the import.meta.env.* syntax as that's for build-time replacements. The paragraph later explains for runtime replacements.
> I'm assuming this means I can only access process from a .svelte file?
You should be using import.meta.env in your example code. process.env should only be used in server code as that's determined in runtime, as in the browser runtime there's no process.
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you authored the thread.Message ID: ***@***.***>
|
Updated the docs to cover the discussion we had. Ready for a quick review. |
much better than what we had before 👍 |
Vite doesn't use
process.
it'simport.meta
Fixes
process not defined
errors when using environment variables@bluwy edit: Explain that
import.meta.env.
is used for build time.Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0