5

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)
web_walkerX
  • 840
  • 10
  • 19
Muhammad tanzeel
  • 53
  • 1
  • 1
  • 3
  • 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 08 '21 at 04:35

5 Answers5

7

I had a similar problem. I turned out I just 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.

fonsmans
  • 71
  • 1
  • 4
5

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

Faisal Hani
  • 178
  • 6
  • 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. – Muhammad tanzeel Dec 22 '21 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 '22 at 02: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

Kyle Pennell
  • 5,747
  • 4
  • 52
  • 75
0

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

Devin
  • 90
  • 7
0

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

Joshua Dance
  • 8,847
  • 4
  • 67
  • 72
Vikramark
  • 137
  • 13