为什么不能在 .env 文件中使用第二个变量
why cant use second variable in .env file
.env 文件中的第一个变量可以使用,但不能使用其他变量。
.env 文件;
REACT_APP_PORT=44318
APP_BASE_URL=https://localhost:44318/
通过以下代码在控制台中打印 process.env 内容;
export default () => {
useEffect(() => {
console.log('object', process.env)
})
这是我看到的;
pcakage.json 个脚本;
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Note: You must create custom environment variables beginning with REACT_APP_. Any other variables except NODE_ENV will be ignored to avoid accidentally exposing a private key on the machine that could have the same name. Changing any environment variables will require you to restart the development server if it is running.
因此,为所有自定义变量添加前缀 REACT_APP_
并重新启动应该可以。
.env 文件中的第一个变量可以使用,但不能使用其他变量。
.env 文件;
REACT_APP_PORT=44318
APP_BASE_URL=https://localhost:44318/
通过以下代码在控制台中打印 process.env 内容;
export default () => {
useEffect(() => {
console.log('object', process.env)
})
这是我看到的;
pcakage.json 个脚本;
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
Note: You must create custom environment variables beginning with REACT_APP_. Any other variables except NODE_ENV will be ignored to avoid accidentally exposing a private key on the machine that could have the same name. Changing any environment variables will require you to restart the development server if it is running.
因此,为所有自定义变量添加前缀 REACT_APP_
并重新启动应该可以。