SyntaxError: Unexpected token ; (EJS)

4,588 views
Skip to first unread message

Tim Broddin

unread,
Sep 20, 2011, 12:55:28 PM9/20/11
to Express
Hi,

I'm playing around a bit with the Express framework and EJS and I get
this error:

at Object.Function (unknown source)
at Object.compile (/Users/tim/Sites/curatica/node_modules/ejs/lib/
ejs.js:198:12)
at Function.compile (/Users/tim/Sites/curatica/node_modules/express/
lib/view.js:65:33)
at ServerResponse._render (/Users/tim/Sites/curatica/node_modules/
express/lib/view.js:414:18)
at ServerResponse.render (/Users/tim/Sites/curatica/node_modules/
express/lib/view.js:315:17)
at Promise. (/Users/tim/Sites/curatica/app.js:43:7)
at Promise. (/Users/tim/Sites/curatica/node_modules/mongoose/lib/
promise.js:120:8)
at Promise. (events.js:64:17)
at Promise.emit (/Users/tim/Sites/curatica/node_modules/mongoose/lib/
promise.js:59:38)
at Promise.complete (/Users/tim/Sites/curatica/node_modules/mongoose/
lib/promise.js:70:20)

This is my view template:

<h1><%= title %></h1>
<ul>
<% users.forEach(function(user) { -%>
<li><%= user.nickname %></li>
<% }); -%>
</ul>

And this call renders my view:


app.get('/', function(req, res){
model.User.find({}, function (err, result) {
res.render('index', {
title: 'Express',
users: result
});
});
});

I've got no clue what I'm doing wrong here. Anyone can help?

Ryan Schmidt

unread,
Sep 27, 2011, 2:23:08 AM9/27/11
to expre...@googlegroups.com
On Sep 20, 2011, at 11:55, Tim Broddin wrote:

> I'm playing around a bit with the Express framework and EJS and I get
> this error:
>
> at Object.Function (unknown source)
> at Object.compile (/Users/tim/Sites/curatica/node_modules/ejs/lib/
> ejs.js:198:12)

I use Jade but got a similar error that I was baffled by for awhile. In my case it meant there was a syntax error in my view (or layout).

> at Function.compile (/Users/tim/Sites/curatica/node_modules/express/
> lib/view.js:65:33)
> at ServerResponse._render (/Users/tim/Sites/curatica/node_modules/
> express/lib/view.js:414:18)
> at ServerResponse.render (/Users/tim/Sites/curatica/node_modules/
> express/lib/view.js:315:17)
> at Promise. (/Users/tim/Sites/curatica/app.js:43:7)
> at Promise. (/Users/tim/Sites/curatica/node_modules/mongoose/lib/
> promise.js:120:8)
> at Promise. (events.js:64:17)
> at Promise.emit (/Users/tim/Sites/curatica/node_modules/mongoose/lib/
> promise.js:59:38)
> at Promise.complete (/Users/tim/Sites/curatica/node_modules/mongoose/
> lib/promise.js:70:20)
>
> This is my view template:
>
> <h1><%= title %></h1>
> <ul>
> <% users.forEach(function(user) { -%>
> <li><%= user.nickname %></li>
> <% }); -%>
> </ul>


I haven't used ejs myself so I don't know whether this is valid syntax or not. But based on this example...

https://github.com/visionmedia/ejs/blob/master/examples/list.ejs

...I'd say the "-" before the closing "%>" tags should not be there.


vision media [ Tj Holowaychuk ]

unread,
Sep 27, 2011, 11:13:26 AM9/27/11
to expre...@googlegroups.com
-%> is supposed to be for whitespace control, though I'm not certain we even support that right now, I don't think so



--
You received this message because you are subscribed to the Google Groups "Express" group.
To post to this group, send email to expre...@googlegroups.com.
To unsubscribe from this group, send email to express-js+...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/express-js?hl=en.




--
Tj Holowaychuk
Vision Media
President & Creative Lead
Reply all
Reply to author
Forward
0 new messages