#ENV variables not working in NextJS?

1 messages · Page 1 of 1 (latest)

meager quiver
#

I'm trying to connect my .env.local file env variables to my application, but it's showing this error.
This is my supabase.ts:

import { createClient } from "@supabase/supabase-js";

const supabaseURL = process.env.NEXT_PUBLIC_SUPABASE_URL!;
const supabaseKEY = process.env.NEXT_PUBLIC_SUPABASE_KEY!;

if (!supabaseKEY || !supabaseURL) {
  throw new Error("Supabase URL and key must be provided");
}

const supabase = createClient(supabaseURL, supabaseKEY);

export default supabase;

I've stored my variables in .env.local, without quotes (as shown)

sour edgeBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

vocal blaze
#

in your code you're using NEXT_PUBLIC_ prefix while your env variables aren't prefixed

meager quiver