2012-03-19 88 views
1

我是新來的node.js,我只是想學習如何使用Express和Jade。看來,這條線在jade.js導致某種問題:window.jade = require("jade");Jade with Express - ReferenceError:窗口未定義

我可以啓動我的服務器就好了,但是當我在我的瀏覽器訪問它,我得到這個錯誤:

ReferenceError: window is not defined 
    at C:\Users\User\Desktop\node-js-web\node_modules\jade\jade.js:3142:1 
    at Object.<anonymous> (C:\Users\User\Desktop\node-js-web\node_modules\jade\jade.js:3143:2) 
    at Module._compile (module.js:441:26) 
    at Object..js (module.js:459:10) 
    at Module.load (module.js:348:31) 
    at Function._load (module.js:308:12) 
    at Module.require (module.js:354:17) 
    at require (module.js:370:17) 
    at Object.<anonymous> (C:\Users\User\Desktop\node-js-web\node_modules\jade\index.js:4:5) 
    at Module._compile (module.js:441:26) 

當我註釋掉那條線時,我得到這個錯誤:

TypeError: Object #<Object> has no method 'compile' 
    at Function.compile (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\view.js:68:33) 
    at ServerResponse._render (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\view.js:417:18) 
    at ServerResponse.render (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\view.js:318:17) 
    at C:\Users\User\Desktop\node-js-web\server.js:37:7 
    at callbacks (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\router\index.js:272:11) 
    at param (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\router\index.js:246:11) 
    at pass (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\router\index.js:253:5) 
    at Router._dispatch (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\router\index.js:280:4) 
    at Object.handle (C:\Users\User\Desktop\node-js-web\node_modules\express\lib\router\index.js:45:10) 
    at next (C:\Users\User\Desktop\node-js-web\node_modules\express\node_modules\connect\lib\http.js:203:15) 

我真的不知道該怎麼做。誰能幫忙?

回答

4

Node.js中沒有window對象,因爲它不在瀏覽器中。如果要將jade附加到全球範圍內,請使用global

(但是,爲什麼你想變全球您的應用程序,反正只表達所需要的玉器來呈現你的看法?)

+0

此代碼是jade.js - 顯然是由於一些bug變通? [鏈接](https://github.com/visionmedia/jade/issues/247) – 2012-03-19 18:56:47

+1

在仔細研究你的錯誤之後,我發現它在''3142''行''jade.js''內失敗了, '!? [但是''jade.js''只有'238'行](https://github.com/visionmedia/jade/blob/master/lib/jade.js)。你如何將代碼加載到Node.js中?它似乎並不像你正在做一個簡單的''var jade = require('jade')'' – 2012-03-19 19:05:00

+0

啊我確定從npm下載的軟件包缺失/lib/jade.js – 2012-03-19 19:12:27

相關問題