我嘗試使用Express中的句柄模板。我得到這個錯誤 - 消息:nodejs handlebars:'TypeError:this.engine不是函數'
TypeError: this.engine is not a function at View.render (/home/ubuntu/workspace/node_modules/express/lib/view.js:128:8) ...
與此代碼:
'use strict';
var express = require('express');
var expressHandlebars = require('express-handlebars');
var app = express();
app.engine('handlebars', expressHandlebars({defaultLayout: 'layout'}));
app.set('view engine', 'html');
app.use(express.static('views'));
app.route('/single/:id')
.get(function (req, res) {
res.render(process.cwd() + `/public/single-poll`, {
id: req.params.id
});
});
app.listen(process.env.PORT, function() {
console.log('Node.js listening on port ' + process.env.PORT + '...');
});
當我更換SENDFILE渲染()()函數是工作正常。我知道Express js render : TypeError: this.engine is not a function和Express js render error this.engine is not a function和TypeError: this.engine is not a function when trying to use Moustache in Express JS,但它們對我沒有幫助。
可能是什麼問題?
Thx。但錯誤保持不變。 – Michael
嘗試從res'render()調用中刪除文件擴展名。它解決了嗎? –
不,它沒有。 – Michael