英文:
vercel deployment .env not found
问题
我正在在Vercel上进行部署。当前在 scripts
中更改了 npm start 的设置,并添加了 npm run start:staging,因为我有两个环境。在Vercel中添加了变量并修改了构建命令
env-cmd -f .env.staging react-scripts build
以及开发命令:env-cmd -f .env.staging react-scripts start
。package.json 文件如下:
"scripts": {
"start": "env-cmd -f .env.development react-scripts start",
"start:staging": "env-cmd -f .env.staging react-scripts start",
"start:production": "env-cmd -f .env.production react-scripts start",
"build": "env-cmd -f .env.development react-scripts build",
"build:staging": "env-cmd -f .env.staging react-scripts build",
"build:production": "env-cmd -f .env.production react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
但是在部署过程中出现了错误:
Error: Failed to find .env file at path: .env.staging
at getEnvFile (/vercel/path0/node_modules/env-cmd/dist/get-env-vars.js:40:19)
Error: Command "env-cmd -f .env.staging react-scripts build" exited with 1
显然,当文件
- .env.staging
- .env.development
被推送到存储库并且我从缓存中删除它们时,这种情况开始发生,因为 .gitignore
无法防止它们被上传。可能出现了什么问题?
英文:
I am doing a deployment in vercel. Currently change in scripts
the settings for npm start and add npm run start:staging since I have 2 environments. Add the variables inside vercel and modify the build commands
env-cmd -f .env.staging react-scripts build
and the development command a: env-cmd -f .env.staging react-scripts start
. The package.json file looks like this:
"scripts": {
"start": "env-cmd -f .env.development react-scripts start",
"start:staging": "env-cmd -f .env.staging react-scripts start",
"start:production": "env-cmd -f .env.production react-scripts start",
"build": "env-cmd -f .env.development react-scripts build",
"build:staging": "env-cmd -f .env.staging react-scripts build",
"build:production": "env-cmd -f .env.production react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
However it gives me the error in the deployment:
Error: Failed to find .env file at path: .env.staging
at getEnvFile (/vercel/path0/node_modules/env-cmd/dist/get-env-vars.js:40:19)
Error: Command "env-cmd -f .env.staging react-scripts build" exited with 1
Obviously this started to happen when the files
- .env.staging
- .env.development
they were pushed to the repository and I removed them from the cache because .gitignore
was not preventing their upload. What could be happening?
答案1
得分: 1
考虑到您的存储库中没有.env
文件(您不应该有(来源)),Vercel无法读取它们。
您需要指定特定于部署的环境变量。
编辑
如果您想了解更多信息,建议阅读Vercel文档中的环境变量文章。
英文:
Taking into consideration that you don't have the .env
files in your repo (which you shouldn't (source)) - Vercel can't read them.
You need to specify the Environment Variables specific to deployments.
How do I set up a staging environment on Vercel?
Edit
I suggest reading the Environment Variables article on the Vercel Docs if you want to learn more.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论