【问题标题】:Having errors deploying Node server to heroku将 Node 服务器部署到 heroku 时出错
【发布时间】:2022-01-04 22:27:57
【问题描述】:

我正在将我的 Node Express 服务器部署到 heroku,在我执行 git push heroku master 之后出现了一些错误。我是向 Heroku 部署应用程序的完整初学者。如何解决此错误?

我尝试过的:

  • 我已设置process.env.PORT
  • 添加一个带有web:node index.js 的Procfile
  • heroku restart
2021-11-27T02:39:05.410712+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=logo-eshop.herokuapp.com request_id=fb4f6e95-de99-4135-9273-789af704557d fwd="79.66.155.39" dyno= connect= service= status=503 bytes= protocol=https        
2021-11-27T02:39:05.650439+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=logo-eshop.herokuapp.com request_id=6572c3a7-f7c4-4ef6-ae09-cd4fcf0c6f5f fwd="79.66.155.39" dyno= connect= service= status=503 bytes= protocol=https

另外,我已经修复了 package.json 中的 nodemon

"scripts": {
   "start": "node index.js"
}

但我仍然有错误。

【问题讨论】:

  • 您能在package.json 中显示脚本字段吗?

标签: javascript node.js reactjs express heroku


【解决方案1】:

我找到了解决方案。对于那些可能和我有同样问题的人,我只需在 Heroku 中添加我所有的 env 变量(设置 > 配置变量)。

【讨论】:

    【解决方案2】:

    它实际上看起来像它,因为没有找到 nodemon。

    Nodemon 不应在生产或部署中使用,因为您不需要/不想在生产环境中自动刷新服务器。

    为了防止这种情况,只需在 package.json 文件的脚本部分添加另一个字段,然后从“开始”中删除 nodemon。它应该看起来像这样:

    "scripts": {
        "start": "index.js",
        "dev": "nodemon index.js"
      },
    

    现在,在自己的机器上开发时,不要调用 npm start(或 yarn start),而是调用 npm run dev(yarn run dev)。

    这样,heroku 将永远不会在生产和部署期间尝试使用 nodemon,但您将能够在开发期间自动重启服务器

    Heroku 将调用 npm start,因此如果此处有 nodemon 命令,它将失败。

    【讨论】:

    • 是的,nodemon 是另一个导致错误的问题,我现在修复了它。但我在部署网站时仍然遇到错误。
    猜你喜欢
    • 1970-01-01
    • 2021-06-22
    • 1970-01-01
    • 2019-12-01
    • 1970-01-01
    • 2013-09-07
    • 2017-10-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多