6

i'm using supabase postgresql online, in which important create a .env file where is my online DMBS's URL and anon key is saved and a "supabase client" file also create to access DBMS and tables and the import "supabase client" in the require file. I have done all the same things that have in their documentation but facing still an error "Error: supabaseUrl is required" but i alredy enter the url.

..................code....................................

import React, { useState } from 'react'
import './App'
import Login from './Login';
import { BrowserRouter as Router, Route, Link, NavLink, Switch } from 'react-router-dom';
import {supabase} from './supabaseClient';

return(
    <>
    <div className="container" >
        <div className="heading">
            <h1>SignUp Form</h1>
        </div>

    <form>
    <Router>
        <div className="mb-3">
            <label  className="flabel">Name</label>
            <input type="text" className="fcontrol" placeholder="Enter Your Name"/>
        </div>
        <div className="mb-3">
            <label  className="flabel">Phone</label>
            <input type="tel"  className="fcontrol" placeholder="Enter Your Phone Number"/>
        </div>
        <div className="mb-3">
            <label  className="flabel">Email</label>
            <input type="email"  className="fcontrol" placeholder="Enter Your Email"/>
        </div>
        <div className="mb-3">
            <label  className="flabel">Password</label>
            <input type="password"  className="fcontrol" placeholder="Enter Your Password"/>
        </div>
        
        <div className="mb-3">
        <button className="btn1" >SignUp</button>
        <Link exact to="/Login">
            Have an already acoount? Login
        </Link> 
        </div>

        {/* --------------------- switch ------------------- */}

        <switch>
            <Route exact path="/Login" component={Login} />
                

        </switch>

        </Router>
    </form>

    </div>
    </>


   )
}
export default Form;

...........................supabase client.................................

import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.REACT_APP_SUPABASE_URL
const supabaseAnonKey = process.env.REACT_APP_SUPABASE_ANON_KEY

export const supabase = createClient(supabaseUrl, supabaseAnonKey)
1
  • Hi Muhammad! It might be a problem around how the env file is configured. Are you able to share the env file without showing critical information here?
    – dshukertjr
    Jul 8, 2021 at 4:35

5 Answers 5

7

I had a similar problem. It turned out I had to restart my dev instance through the terminal because the environment variables get loaded in at launch after running npm run dev or whatever you are using.

6

this problem is maybe connected with .env file if the "Error: supabaseUrl is required" make sure that the REACT_APP_SUPABASE_URL is the same at the .env file

2
  • 1
    fixed... thanks... the error was that after saving the file in .env extension, it was necessary to close it in ubuntu then it works.. thanks again for your concern. Dec 22, 2021 at 11:59
  • 3
    Just in case anyone is using Vite, there's new changes and need to create the key as VITE_SOMETHING_ELSE and import it as import.meta.env.VITE_SOMETHING_ELSE
    – 8koi
    Dec 26, 2022 at 2:56
2

For me...I had the file as env.local when it needed to be .env.local The first dot is needed

enter image description here

1

Environment variables are not accessible by the browser by default. You need to prefix them with NEXT_PUBLIC Here's a similar Stackoverflow thread

1
  • This fix would work only for Next.js users.
    – A Petrov
    Mar 12 at 13:05
0

8koi's comment was it for me. Gotta prefix the variable with VITE_ if you're useing vite.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.