如何有条件地检查 React 应用程序在 Heroku 环境中是否处于“生产”状态或“开发”状态?

问题描述 投票:0回答:1

这是代码:

if (process.env.NODE_ENV === 'production') {
  module.exports = require('./keys_prod');
} else {
  module.exports = require('./keys_dev');
}

keys_prod IS 在服务器上

keys_dev 仅在我的本地计算机上

问题来了:

当应用程序在 Heroku 上启动时,我得到以下信息:

ERROR in ./src/environment/keys.js 8:2-40
 Module not found: Error: Can't resolve './keys_dev' in '/app/src/environment'

Heroku 配置变量

我在 Heroku 配置变量中设置了以下内容:

package.json

我的 package.json 脚本部分

  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject",
    "heroku-postbuild": "npm run build"
  },

看到了这个,但我在heroku 22上 - 所以那行不通

heroku environment-variables create-react-app
1个回答
0
投票

您正在设置

REACT_APP_NODE_ENV
,但没有设置
NODE_ENV
。将
NODE_ENV
设置为生产。

© www.soinside.com 2019 - 2024. All rights reserved.