【发布时间】:2019-12-05 01:09:35
【问题描述】:
当我尝试使用 React 和 Parcel 进行项目时,console.log(process.env) 返回一个空对象,但如果我向其中添加 API_Key 将返回 undefined
谁能告诉我怎么了?为什么我的环境变量返回 undefined
这是我的 json 包:
"clear-build-cache": "rm -rf .cache/ dist/",
"dev": "parcel src/index.html",
"build": "parcel build index.html",
"dev:mock": "cross-env OPEN-INV=mock parcel src/index.html",
"format": "prettier --write \"src/**/*.{js,jsx}\"",
"lint": "eslint \"src/**/*.{js,jsx}\" --quiet",
"test": "echo \"Error: no test specified\" && exit 1"
`},
here is my .env file which is next to the package .json
REACT_APP_API_KEY:"my api key"
console.log(process.env) // {}
console.log(process.env. REACT_APP_API_Key)// undefined
【问题讨论】:
标签: reactjs environment-variables parceljs