【问题标题】:"Error: Configuration property is not defined" on `heroku local web` - Config / Heroku`heroku local web`上的“错误:未定义配置属性” - Config / Heroku
【发布时间】:2020-04-17 13:51:23
【问题描述】:

我正在尝试在本地设置现有的 Heroku 应用程序。为此,我 git cloned 来自我们在 Github 的仓库中的应用程序。然后我为 heroku 添加了git remote

通常,使用Travis CI 构建到服务器,但现在我想直接从heroku 在本地运行应用程序。

heroku config 返回配置变量就好了。

但是heroku local web返回错误

throw new Error('Configuration property "' + property + '" is not defined');

错误:配置属性“redis.url”未定义

redis.js

import config from 'config';
const redis = new Redis(config.get('redis.url'), {
  keyPrefix: 'kw:',
});

config 文件夹位于我的 repo 的根目录中。

config/default.js

import dotenv from 'dotenv';

dotenv.config({ silent: true });

module.exports = {
  ...,
  redis: {
    url: process.env.REDIS_URL || process.env.REDISCLOUD_URL,
  },
  ...
}

package.js中的相关脚本

    "start:server": "./node_modules/.bin/babel-node src/server.js",
    "start:worker": "./node_modules/.bin/babel-node src/worker/worker.js",
    "start": "./node_modules/.bin/nf start",

如果我运行 npm run start:server 我会得到同样的错误。

如果我注释掉 redis.url 代码,我会得到同样的错误,但 config 中的另一个变量。

我错过了什么?如果您需要澄清,请告诉我。

【问题讨论】:

    标签: node.js heroku redis config dotenv


    【解决方案1】:

    heroku config -s > .env

    似乎会将这些文件复制到本地 .env 中。这似乎很奇怪,这不是默认设置,但确实如此。

    完成后,使用heroku local 运行您的应用程序。

    我在这里找到了答案:https://www.debugcn.com/en/article/31153943.html

    【讨论】:

      【解决方案2】:

      我必须创建一个本地 .env 文件。

      我很困惑,因为我读到 Heroku 不需要 .env 文件。但似乎本地设置并非如此。

      【讨论】:

      • 希望这里有更多的澄清。困惑,似乎正是heroku local 的重点在于您不需要创建自己的 .env ... 仍然不明白这一点。硬编码这些值没有意义。
      猜你喜欢
      • 2021-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-12
      • 2018-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多