Next.js Discord

Discord Forum

ENV variables not working in NextJS?

Answered
Northern snakehead posted this in #help-forum
Open in Discord
Northern snakeheadOP
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)
Answered by Yi Lon Ma
in your code you're using NEXT_PUBLIC_ prefix while your env variables aren't prefixed
View full answer

2 Replies

in your code you're using NEXT_PUBLIC_ prefix while your env variables aren't prefixed
Answer
@Yi Lon Ma in your code you're using `NEXT_PUBLIC_` prefix while your env variables aren't prefixed
Northern snakeheadOP
Even after removing NEXT_PUBLIC_ , it's not working, showing the same error.