【问题标题】:App crashed on heroku when i included express-handlebar in the project, but works locally当我在项目中包含 express-handlebar 时,应用程序在 heroku 上崩溃,但在本地工作
【发布时间】:2021-07-05 19:22:56
【问题描述】:

这是我添加到应用程序中的代码,导致它在 Heroku 服务器上崩溃,删除这些代码会导致应用程序在 Heroku 上正常运行我的应用程序在本地使用这些代码

const exphbs  = require('express-handlebars')({extname:"hbs"})

app.engine('hbs', exphbs);
app.set('view engine', 'hbs');


here is the logs below

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/h5Mer.png

【问题讨论】:

    标签: javascript node.js express heroku express-handlebars


    【解决方案1】:

    对象字面量中的spread operator 是在 Node.js v8.3.0 中引入的。看起来该应用程序在 Heroku 上的旧版本 Node.js 上运行。由于您提到该应用程序在本地工作,很明显开发和生产环境使用的不是相同版本的 Node.js。您应该 specify the version of Node.js(应该是 v10+,因为 express-handlebars v5.0.0 放弃了对 Node 10 以下版本的支持)应用程序在 package.json 中使用,以便 Heroku 在部署中使用。

    来自 Heroku 的 Node.js 部署 docs

    最好让您的开发环境和生产环境尽可能相似。因此,请确保您的 Node.js 本地版本与您告诉 Heroku 在 package.json 文件中使用的版本相匹配。要检查您在本地运行的版本,请在命令行中输入 node --version

    【讨论】:

    • 谢谢这是错误的原因,我设置了“engines”:{“node”:“8.1.1”,“npm”:“5.0.3”},这使得节点运行我的服务器中的一个非常过时的版本,现在更正它
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-09-10
    • 2020-12-08
    • 2020-03-16
    • 1970-01-01
    • 2019-07-26
    • 2015-02-13
    • 1970-01-01
    相关资源
    最近更新 更多