2013-09-22 93 views
4

我一直在試圖製作一個網站使用快遞和玉器。我已經寫了好幾頁和路線,到現在爲止工作得很好。我不斷收到以下錯誤:ReferenceError:玉沒有定義

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,我可以去我所有的網頁,但每當我登錄,即設置一個會話變量與登錄的用戶,我收到上面的錯誤。

我不確定我可以包含哪些其他信息。在該堆棧跟蹤參考cases.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) 

問題就沒有了,但我確實需要我的中間件的功能。我將如何去解決這個問題?

+0

我已經編輯我的問題,包括我的玉配置和問題 – Eldamir

+0

看起來這可能需要做的視圖用會話變量的存儲方式。我會進一步調查 – Eldamir

+0

你可以粘貼'cases.home()'代碼。你的其他兩個男/女對我看起來很好。 – vmx

回答

0

經過一番挖掘,我發現錯誤是與玉。對於我使用的玉版本,當我嘗試使用require(./something)時,Jade源代碼中提到了一個不存在的變量。爲了解決這個問題,我編輯了在./node_modules/jade/lib/jade.js:151

一條從

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

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

行似乎並沒有在所有需要。沒有它,一切都會像它應該那樣運作Jade的github頁面曾經提到過這個問題,並且我暗示了這個提示。這似乎是一個已知的問題,他們正在處理即將到來的版本。

對於任何有同樣的問題,簡單的評論指出一條線,你是金色的

0

另外,你能在var之前loggedIn()clientChosen()的例程定義嗎?將這些定義使用它們來定義app.get('/');

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

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

如果你還沒有使用它,可以在安裝(npm install -g jshint)和運行jshint <path/to/js-file>過嗎?它報告任何錯誤嗎?

相關問題