我一直在尝试使用快递和玉石制作网站。我已经制作了几个页面和路线,到目前为止它运行良好。我不断收到以下错误:
ReferenceError: jade is not defined
at eval (eval at <anonymous> ([...]project/node_modules/jade/lib/jade.js:165:30), <anonymous>:2:1)
at Object.exports.render ([...]project/node_modules/jade/lib/jade.js:211:10)
at Object.exports.renderFile ([...]project/node_modules/jade/lib/jade.js:247:18)
at View.exports.renderFile [as engine] ([...]project/node_modules/jade/lib/jade.js:232:21)
at View.render ([...]project/node_modules/express/lib/view.js:76:8)
at Function.app.render ([...]project/node_modules/express/lib/application.js:506:10)
at ServerResponse.res.render (/media/ruben/5CCAD622CAD5F7EA/Users/ruben/Google Drev/developer/workspace/kwasi/project/node_modules/express/lib/response.js:759:7)
at exports.home ([...]project/routes/cases.js:7:7)
at callbacks ([...]project/node_modules/express/lib/router/index.js:164:37)
at clientChosen ([...]project/app.js:81:5)
当我清除缓存和 cookie 时,我可以访问我的所有页面,但是每当我登录时,即使用登录用户设置会话变量时,我都会收到上述错误。
我不确定我可以包含哪些其他信息。堆栈跟踪引用的 case.js 中的行很简单
res.render("home.jade", {})
编辑:
在我的 app.js 中,我使用以下内容指定了翡翠作为渲染引擎:
app.configure(function() {
app.set("views", __dirname + "/views"); // Set the views folder
app.set("view engine", "jade"); // Set the rendering engine
...
我的观点是这样的:
extend layout
block title
title Forside - #{company}
block content
h3 Sager
- for (var i = 0; i < cases.length; i++) {
.casethumb
p #{cases[i].label}
- }
编辑2:对。我能够确定的是它可能与我的自定义中间件有关。我有这两个功能
// Makes sure that the user is logged in
loggedIn = function(req, res, next){
if (req.session.user) {
next()
}
else {
if (req.url != "/login") {
req.flash('info', "Før du kan bruge systemet, skal du logge ind")
}
res.redirect("/login")
}
}
// Makes sure that the user has chosen a client to work on
clientChosen = function(req, res, next) {
if (req.session.selectedClient) {
next()
}
else {
res.redirect("/chooseClient")
}
}
我像这样使用它们:
app.get("/", loggedIn, clientChosen, cases.home)
当我像这样从我的路线中删除该功能时
app.get("/", cases.home)
问题消失了,但我确实需要中间件的功能。我将如何解决这个问题?