[英]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.