Express.js、Node.js Jade - 遵循expressjs.com 教程并出现错误
好吧,我正在尝试进入 Node.js / Express.js - 但是我在观看截屏视频时遇到了一些问题,第一个问题现已解决,当它被发现时非常明显(Express.js、Node.js Jade vim)。
但是,我现在收到以下错误:
Express 500 SyntaxError: Unexpected identifier * at Object.Function (unknown source) * at Object.compile (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/jade.js:230:10) * at ServerResponse._render (/usr/local/lib/node/.npm/express/2.3.2/package/lib/view.js:368:22) * at ServerResponse.render (/usr/local/lib/node/.npm/express/2.3.2/package/lib/view.js:234:17) * at Object. (/home/duncan/helloExpress/app.js:46:7) * at nextMiddleware (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:139:34) * at param (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:147:16) * at pass (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:155:10) * at Object.router [as handle] (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:161:6) * at next (/usr/local/lib/node/.npm/connect/1.4.0/package/lib/http.js:204:15)
我的 app.js 代码如下: 声明用户对象数组
var users = [ { name: 'Duncan', email: '[email protected]'}, { name: 'Bob', email: '[email protected]'} ];
并... 调用并呈现新 users.jade 的位
app.get('/users', function(req, res){ res.render('users', { users: users }); });
我不知道我今天是否只是盲目的,但我真的很想让这个例子正常工作。
注意。 app.js 46:7 是“res.render”,字符 7 是 . res 和 render 之间。 - 来自错误消息。
users.jade 文件如下:
h1 Users ul#users - each user in users li= user.name
如果我删除: 用户中的用户 和 li= user.name
它渲染页面,一旦我添加它们,它就会给我上面的错误消息,并说 res.render('users' - 在点 (46:7) 上有问题。
PS。我正在关注这里的第二个教程:http://expressjs.com/screencasts.html
我的缩进:
[indent] - [indent] each user in users [indent][indent] li= [indent] user.name
Well I'm trying to get into Node.js / Express.js - however I've been having a few issue going through the screencast, the first issue, now resolved, was pretty obvious when it was spotted (Express.js, Node.js Jade vim).
However, I'm now getting the following errors:
Express 500 SyntaxError: Unexpected identifier * at Object.Function (unknown source) * at Object.compile (/usr/local/lib/node/.npm/jade/0.10.6/package/lib/jade.js:230:10) * at ServerResponse._render (/usr/local/lib/node/.npm/express/2.3.2/package/lib/view.js:368:22) * at ServerResponse.render (/usr/local/lib/node/.npm/express/2.3.2/package/lib/view.js:234:17) * at Object. (/home/duncan/helloExpress/app.js:46:7) * at nextMiddleware (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:139:34) * at param (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:147:16) * at pass (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:155:10) * at Object.router [as handle] (/usr/local/lib/node/.npm/express/2.3.2/package/lib/router/index.js:161:6) * at next (/usr/local/lib/node/.npm/connect/1.4.0/package/lib/http.js:204:15)
My app.js code is as follows:
Declare the users array of object
var users = [ { name: 'Duncan', email: '[email protected]'}, { name: 'Bob', email: '[email protected]'} ];
and...
the bit that calls and renders the new users.jade
app.get('/users', function(req, res){ res.render('users', { users: users }); });
I don't know if I'm just being blind today, but I would really like to get this example working.
NB. app.js 46:7 is the 'res.render' char 7 is the . between res and render. - from the error message.
The users.jade file is as follows:
h1 Users ul#users - each user in users li= user.name
If I get rid of the:
user in users
and li= user.name
it renders the page, as soon as I add them, it gives me the above error message, and says there is something wrong with res.render('users' - on the dot (46:7).
PS. I'm following the second tutorial on here: http://expressjs.com/screencasts.html
My indentation:
[indent] - [indent] each user in users [indent][indent] li= [indent] user.name
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要将
li= user.name
从each 语句向下缩进另一级。这应该有效:
You need to indent the
li= user.name
another level down from the each statement.This should work:
我收到此错误是因为在我的layout.jade 中
我有:
并且显然 ^^^ 那里缺少一个逗号!!!!!
Jade 很棒,但是哇那个错误消息对初学者来说很糟糕。
应该是:
I was getting this error because in my layout.jade
I had:
AND CLEARLY THAT ^^^ SPOT RIGHT THERE IS MISSING A COMMA!!!!
Jade is great and all, but wow that error message is bad for beginners.
Should have been: