[英]Why react doesn't see .env
我有.env
它有REACT_APP_API_URL = http://localhost:5000/
。 我在这个代码片段中使用它
import axios from "axios";
const host = axios.create({
baseURL: process.env.REACT_APP_API_URL
});
const authHost = axios.create({
baseURL: process.env.REACT_APP_API_URL
});
当我尝试 output console.log(process.env.REACT_APP_API_URL);
然后显示的值未定义,这是为什么呢? .env
文件位于所有客户端文件所在的目录中
first install dotenv: npm i dotenv
after that import this to file: const dotenv = require("dotenv")
and config dot env: dotenv.config()
请检查您的.gitignore
文件,有时create-react-app
会将.env
文件添加到 .gitignore 条目。 也许这就是原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.