[英]Why is my env variable showing up as undefined?
I'm trying to get data from a table with Supabase .我正在尝试使用Supbase从表中获取数据。 When I try store the URL and the Key on a .env file it comes back as undefined.
当我尝试将 URL 和密钥存储在 .env 文件中时,它返回为未定义。
File: App.js文件:App.js
import React, { useEffect } from "react";
import ButtonsSection from "./ButtonsSection";
import Header from "./Header";
import InputsSection from "./InputsSection";
import ResultsSection from "./ResultsSection";
export default function App() {
useEffect(() => {
console.log(process.env.REACT_APP_SUPABASE_URL);
}, []);
return (
<div>
<Header />
<InputsSection />
<ButtonsSection />
<ResultsSection />
</div>
);
}
File: Database.env文件:Database.env
REACT_APP_SUPABASE_URL='https://**********.supabase.co'
REACT_APP_SUPABASE_ANON_KEY='***************.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InF2bW56a2xka25hZG1wcmZtc3JqIiwicm9sZSI6ImFub24iLCJpYXQiOjE2NTU0MDQ4NDQsImV4cCI6MTk3MDk4MDg0NH0.Th_x*******************************'
assuming you are using create-react-app.假设您使用的是 create-react-app。 File name should be ".env" not "Database.env" and it should be in the root folder of the project.
文件名应该是“.env”而不是“Database.env”,它应该在项目的根文件夹中。
npm install dotenv
npm install dotenv
.env
extension in the root directory.env
的文件 the problem in your case seems to be that you are not importing dotenv/config
and your file name is database.env which is not correct, just name it as .env
您的问题似乎是您没有导入
dotenv/config
并且您的文件名是 database.env 这是不正确的,只需将其命名为.env
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.