ReferenceError: jade not defined

I am trying to create a website using express and jade. I made some pages and routes, and so far it has worked fine. I keep getting the following error:

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) 

When I clear my cache and cookies, I can go to all my pages, but whenever I log in, that is, set a session variable with a registered user, I get the above error.

I'm not sure what other information I can include. The line in case.js referenced by the stack trace is just

 res.render("home.jade", {}) 

EDIT:

In my app.js, I define jade as a rendering engine with the following:

 app.configure(function() { app.set("views", __dirname + "/views"); // Set the views folder app.set("view engine", "jade"); // Set the rendering engine ... 

and my view is as follows:

 extend layout block title title Forside - #{company} block content h3 Sager - for (var i = 0; i < cases.length; i++) { .casethumb p #{cases[i].label} - } 

EDIT 2: Right. What I was able to determine is that this may have something to do with my middleware. I have two functions

 // 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") } } 

And I use them as follows:

 app.get("/", loggedIn, clientChosen, cases.home) 

When I remove a function from my route, like this

 app.get("/", cases.home) 

The problem goes away, but I need the functionality of my middleware. How can i fix this?

+4
source share
2 answers

After some digging, I found out that the error is related to jade. With the jade version that I use when I try to require(./something) , a nonexistent variable is referenced in the Jade source code. To fix this, I edited one line in ./node_modules/jade/lib/jade.js:151

from

 if (options.client) return new Function('locals', fn) 

to

 //if (options.client) return new Function('locals', fn) 

The line does not seem at all necessary. Everything works without it. One issue was mentioned on the Jade github page, and I gave her a hint. This was a known issue they are dealing with in the upcoming version.

For those who have the same problem, comment that one line and you are golden

0
source

Alternatively, can you var before loggedIn() and clientChosen() subroutine definitions? Put these definitions before using them to define app.get('/');

 var loggedIn = function (req, res, next) { // your code }; var clientChosen = function (req, res, next) { // your code }; 

If you are not using it already, can you install ( npm install -g jshint ) and run jshint <path/to/js-file> ? Does it report any errors?

0
source

All Articles