带有快速参考错误的玉:窗口没有定义

时间:2022-05-18 20:27:13

I am new to node.js and I'm just trying to learn how to use Express and Jade. It seems that this line in jade.js is causing some kind of problem: window.jade = require("jade");

我是node的新手。我和js只是想学习如何使用Express和Jade。这条线好像是玉线。js带来了一些问题:窗口。玉=要求(“玉”);

I can start up my server just fine, but when I visit it in my browser I get this error:

我可以很好地启动我的服务器,但是当我在浏览器中访问它时,我得到了这个错误:

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)

When I comment out that line I get this error instead:

当我注释掉这一行的时候,我得到了这个错误:

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)

I really don't know what to do here. Can anyone help?

我真的不知道该怎么做。谁能帮忙吗?

1 个解决方案

#1


4  

There is no window object in Node.js because it's not in a browser. If you want to attach jade to the global scope, use global.

节点中没有窗口对象。因为它不在浏览器中。如果您想将jade附加到全局范围,请使用global。

(But why do you want to make the variable global to your application, anyways? Only Express needs the jade object to render your views.)

(但是,为什么要将这个变量全局化到应用程序中呢?只有Express需要jade对象来呈现您的视图。

#1


4  

There is no window object in Node.js because it's not in a browser. If you want to attach jade to the global scope, use global.

节点中没有窗口对象。因为它不在浏览器中。如果您想将jade附加到全局范围,请使用global。

(But why do you want to make the variable global to your application, anyways? Only Express needs the jade object to render your views.)

(但是,为什么要将这个变量全局化到应用程序中呢?只有Express需要jade对象来呈现您的视图。