[英]process.env.NODE_ENV === "developement" even in production
I want to deploy a React app (made with Create React App) + a Node server with Heroku,我想部署一个 React 应用程序(使用 Create React App 制作)+一个带有 Heroku 的节点服务器,
I did it, but my app can't fetch data from the server,我做到了,但我的应用程序无法从服务器获取数据,
In production, my process.env.NODE_ENV is equal to "development" which causes a lot of wrong stuff in my code,在生产中,我的 process.env.NODE_ENV 等于“开发”,这会导致我的代码中有很多错误的东西,
Do you know what can put process.env.NODE_ENV always at "development"?你知道什么可以让 process.env.NODE_ENV 始终处于“开发”状态吗? At the build, this environment variable is supposed to switch to "production", no?
在构建时,这个环境变量应该切换到“生产”,不是吗?
Your package.json
add this.你的
package.json
添加这个。
"scripts": {
"start": "export NODE_ENV=development; {your start code}",
Your env variables can be set per environment , in this case in Heroku: https://devcenter.heroku.com/articles/config-vars#using-the-heroku-dashboard您的环境变量可以按环境设置,在这种情况下在 Heroku 中: https ://devcenter.heroku.com/articles/config-vars#using-the-heroku-dashboard
If you want to make sure build
always runs with the same NODE_ENV
, you can follow @seunggabi 's answer.如果您想确保
build
始终使用相同的NODE_ENV
运行,您可以遵循@seunggabi 的回答。 I'd also use cross-env
to make it work cross-platform in such case.在这种情况下,我还会使用
cross-env
使其跨平台工作。 Per-process variable can be forced on heroku-postbuild
task (after &&
).可以在
heroku-postbuild
任务上强制执行每个进程变量(在&&
之后)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.