意外的令牌'}'在d:\ .users.ejs中编译EJ时,如果上述错误无用,则可能需要尝试EJS-lint:https://github.com/ryanzim/
这是我的控制器
文件,
async function getUsers(req, res, next) {
try {
const users = await User.find();
res.render('users', {
users: users
})
res.render('users')
} catch (err) {
next(err)
}
// res.render('users')
}
这是我的users.ejs
文件
<%- include('./partials/header.ejs'); %>
<div class="manageUser-container">
<div id="title">
<h2>Manage Users</h2>
</div>
<div class="new-message-container new-user">
<a href="#" onclick="openModal()">+</a>
</div>
<div id="users-table">
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Manage</th>
</tr>
</thead>
<tbody id="users-table">
-->
<% users.forEach((user)=>{ %>
<tr id="<%= user._id %>">
<td class="name">
<% if( user.avatar){ %>
<img src="./uploads/avatars/<%= user.avatar %>" />
<%=}else{ %>
<img src="./images/nophoto.png" alt="User" />
<% } %>
<span><%= user.name %></span>
</td>
<td><%= user.email %></td>
<td class="manage">
<img src="./images/trash.png" alt="Delete" />
</td>
</tr>
-->
<h1>Hello</h1>
`enter code here`
<% }) %>
</tbody>
</table>
</div>
</div>
<%- include('./partials/addUserModal.ejs'); %>
</body>
</html>
和错误
在浏览器中显示
d:\ programming \ nodejs \ chat_application \ views \ tiews \ users.ejs中的意外令牌'}'在编译时
ejs如果上述错误无用,则可能需要尝试EJS-lint: https://github.com/ryanzim/ejs-lint 或者,如果您打算创建创建一个 异步函数,通过
async:true
作为选项。SyntaxError:意外的令牌'}' D:\编程\ nodejs \ chat_application \ views \ users.ejs编译时 EJS如果以上错误无用,则可能需要尝试EJS-lint: https://github.com/ryanzim/ejs-lint 或者,如果您打算创建创建一个 异步函数,将
async:true
作为选项。在新功能 ()在template.com上 (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:662:12) 在object.com上 (d:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:396:16) 在handlecache (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:233:18) 在tryhandlecache (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:272:16) 在view.exports.renderfile [作为引擎] (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:489:10) 在View.Render (D:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ lib \ view.js:135:8) 在Tryrender (d:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ lib \ application.js:640:10) 在function.render (d:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ lib \ application.js:592:3) 在serverresponse.render上 (d:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ response.js:1017:7)
如何解决此错误?
This is my controller
file
async function getUsers(req, res, next) {
try {
const users = await User.find();
res.render('users', {
users: users
})
res.render('users')
} catch (err) {
next(err)
}
// res.render('users')
}
this is my users.ejs
file
<%- include('./partials/header.ejs'); %>
<div class="manageUser-container">
<div id="title">
<h2>Manage Users</h2>
</div>
<div class="new-message-container new-user">
<a href="#" onclick="openModal()">+</a>
</div>
<div id="users-table">
<table>
<thead>
<tr>
<th>Name</th>
<th>Email</th>
<th>Manage</th>
</tr>
</thead>
<tbody id="users-table">
-->
<% users.forEach((user)=>{ %>
<tr id="<%= user._id %>">
<td class="name">
<% if( user.avatar){ %>
<img src="./uploads/avatars/<%= user.avatar %>" />
<%=}else{ %>
<img src="./images/nophoto.png" alt="User" />
<% } %>
<span><%= user.name %></span>
</td>
<td><%= user.email %></td>
<td class="manage">
<img src="./images/trash.png" alt="Delete" />
</td>
</tr>
-->
<h1>Hello</h1>
`enter code here`
<% }) %>
</tbody>
</table>
</div>
</div>
<%- include('./partials/addUserModal.ejs'); %>
</body>
</html>
and error
show in browsers
Unexpected token '}' in D:\programming\nodejs\chat_application\views\users.ejs while compiling
ejs If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint Or, if you meant to create an
async function, passasync: true
as an option.SyntaxError: Unexpected token '}' in
D:\programming\nodejs\chat_application\views\users.ejs while compiling
ejs If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint Or, if you meant to create an
async function, passasync: true
as an option. at new Function
() at Template.compile
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:662:12)
at Object.compile
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:396:16)
at handleCache
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:233:18)
at tryHandleCache
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:272:16)
at View.exports.renderFile [as engine]
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:489:10)
at View.render
(D:\programming\nodejs\chat_application\node_modules\express\lib\view.js:135:8)
at tryRender
(D:\programming\nodejs\chat_application\node_modules\express\lib\application.js:640:10)
at Function.render
(D:\programming\nodejs\chat_application\node_modules\express\lib\application.js:592:3)
at ServerResponse.render
(D:\programming\nodejs\chat_application\node_modules\express\lib\response.js:1017:7)
How can i solve this error.?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我可以帮助您调试此问题,但是您必须自己解决。以下步骤:
users.ejs
中}
因此,此
users.ejs
具有几个部分视图,或include
指令。要缩小问题:只需删除所有include
,请查看问题是否持续? (如果需要,请重新启动服务器)如果问题消失了,我们知道错误在其中一个
include
文件之一。如果不是,我们继续进行步骤,通过查看任何
}
,按行删除该服务器,重新启动服务器(只是为了确保我们获得最新的代码),请注意是否出错,请重复。I can help you debug this issue, but you will have to resolve it yourself. Here are the steps:
users.ejs
}
So this
users.ejs
has several partial views, orinclude
directive. To narrow down the problem: Just remove allinclude
, see if the problem persist? (restart the server if needed)if the problem gone, we know that the error is inside one of those
include
files.If not, we continue the step, by looking at any
}
, remove it line by line, restart the server (just to make sure we get the latest code), watch if the error gone, repeat.我在users.ejs文件中创建了此错误。
在这里我声明= ejs表达式中的文件如下:
但是解决方案是
我在&lt;%之后删除= sign = sign&lt;%,因为如果我想打印一些值,请使用&lt; %=标志...我认为这对许多开发人员有帮助
i created this error inside the users.ejs file
Here i declared = inside the ejs expression like :
But the solution is
i remove = sign after <% because else is a condition not value if i want to print some value then use <%= sign... i think it will help full for many developer