我用的是 express-handlebars
包(版本。4.0.4
),然后像这样渲染我的代码。
app.get("/", (req, res) => {
res.render('index', { title: 'Snowy' }, {
allowProtoMethodsByDefault: true,
allowProtoPropertiesByDefault: true
});
})
但我还是得到了同样的错误。Stackoverflow上的任何解决方案对我来说都没有用。
在你的情况下,你必须安装旧版本的handlebar。把这个粘贴到你的终端,它应该会安装正确版本的handlebars。
npm uninstall express-handlebars && npm install [email protected]
这个版本问题可能与你机器上的npm或node.js版本有关。