我是node.js的新手,我只是想学习如何使用Express和Jade。似乎jade.js中的这一行引起了某种问题:window.jade = require("jade");
我可以很好地启动我的服务器,但是当我在浏览器中访问它时,我收到了这个错误:
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)
我真的不知道该怎么做。有人可以帮忙吗?
答案 0 :(得分:4)
Node.js中没有window
对象,因为它不在浏览器中。如果要将jade
附加到全局范围,请使用global
。
(但是为什么你想让变量全局变为你的应用程序呢?只有Express需要jade对象来渲染你的视图。)