我正在尝试使用 express-handlebars 模块但出现错误。
我的代码:
var exphbs = require('express-handlebars');
app.engine('.hbs', exphbs({ extname: '.hbs', defaultLayout: "main"}));
app.set('view engine', '.hbs');
我的错误:"app.engine('.hbs', exphbs({ extname: '.hbs', defaultLayout: "main"}));
^
TypeError: exphbs is not a function"
我似乎无法弄清楚为什么它不能正常工作。有任何想法吗?
最佳答案
您应该使用“exphbs.engine”而不是“exphbs”。
app.engine('.hbs', exphbs.engine({ extname: '.hbs', defaultLayout: "main"}));
关于javascript - 类型错误 : exphbs is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69959820/