admin管理员组文章数量:1356566
I am working on a project in Node.JS Express. I had several pages all of which are running fine but only one page (till now) is giving error in loading up. When I ran that page a error pops up, that is :
SyntaxError: Unexpected token catch in E:\nodeapp\views\adm.ejs while piling ejs
If the above error is not helpful, you may want to try EJS-Lint:
Or, if you meant to create an async function, pass async: true as an option.
at new Function (<anonymous>)
at Templatepile (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:633:12)
at Objectpile (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:392:16)
at handleCache (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:215:18)
at tryHandleCache (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:254:16)
at View.exports.renderFile [as engine] (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:485:10)
at View.render (E:\Submit\Fresh\nodeapp\node_modules\express\lib\view.js:135:8)
at tryRender (E:\Submit\Fresh\nodeapp\node_modules\express\lib\application.js:640:10)
at Function.render (E:\Submit\Fresh\nodeapp\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (E:\Submit\Fresh\nodeapp\node_modules\express\lib\response.js:1008:7)
I am working on a project in Node.JS Express. I had several pages all of which are running fine but only one page (till now) is giving error in loading up. When I ran that page a error pops up, that is :
SyntaxError: Unexpected token catch in E:\nodeapp\views\adm.ejs while piling ejs
If the above error is not helpful, you may want to try EJS-Lint:
https://github./RyanZim/EJS-Lint
Or, if you meant to create an async function, pass async: true as an option.
at new Function (<anonymous>)
at Template.pile (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:633:12)
at Object.pile (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:392:16)
at handleCache (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:215:18)
at tryHandleCache (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:254:16)
at View.exports.renderFile [as engine] (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:485:10)
at View.render (E:\Submit\Fresh\nodeapp\node_modules\express\lib\view.js:135:8)
at tryRender (E:\Submit\Fresh\nodeapp\node_modules\express\lib\application.js:640:10)
at Function.render (E:\Submit\Fresh\nodeapp\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (E:\Submit\Fresh\nodeapp\node_modules\express\lib\response.js:1008:7)
My adm.ejs file is :
<%- include('../views/header') %>
<div class="container">
<div class="row">
<div class="col-md-12">
<hr>
<button type="button" class="btn btn-warning" id="table_view_btn"> Voters / Candidates</button>
<button type="button" class="btn btn-danger float-right" onclick="javascript:window.location = '/admin/logout';"> Logout</button>
<hr>
<div id="voter_table">
<table class="table table-hover table-bordered table-striped">
<h4>Voters</h4>
<small>Click on the row item to verify the identity of Voter.</small>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Aadhaar</th>
<th scope="col">Constituency</th>
<th scope="col">Voted?</th>
<th scope="col">Verified?</th>
</tr>
</thead>
<tbody>
<!--<% for(var i=0 ; i < voters.length; i++) { %> -->
<tr onclick="window.location='/admin/verifyvoter/';" style="cursor: pointer;">
<th scope="row">
1
</th>
<td>
Janit
</td>
<td>
ABC123
</td>
<td>
COR
</td>
<td>
True
</td>
<td>
True
</td>
</tr>
</tbody>
</table>
</div>
<div id="candidate_table" style="display:none;">
<!-- <div>
<h3>Add Candidate</h3>
<form method="post" action="/addcandidate" class="form-inline">
<div class="form-group">
<input type="text" class="form-control" id="cand_name" name="cand_name" placeholder="Enter Name">
</div>
<div class="form-group">
<select class="custom-select form-control" id="cand_constituency" name="cand_constituency">
<option selected>Constituency</option>
<option value="Jabalpur">Jabalpur</option>
<option value="Delhi">Delhi</option>
</select>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary form-control">Add Candidate</button>
</div>
</form>
</div>
<hr> -->
<table class="table table-hover table-bordered table-striped">
<h4>Candidates</h4>
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Name</th>
<th scope="col">Constituency</th>
</tr>
</thead>
<tbody>
<!--<% for(var i=0 ; i < candidates.length; i++) { %>-->
<tr>
<th scope="row">
2
</th>
<td>
Souvik
</td>
<td>
Jabalpur
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</body>
</html>
I tried searching on the internet regarding this error but everyone showed that there is a problem in the include syntax which is correct for me. Also my router file for this page has nothing else other than a get request which renders this page to the client.
Where's the problem then ?
Thanks
Share Improve this question asked Apr 24, 2021 at 13:46 Janit LodhaJanit Lodha 211 gold badge1 silver badge2 bronze badges 3-
Try putting the JS loop with its
{
in a JS ment, not a HTML ment – Bergi Commented Apr 24, 2021 at 15:15 - Which loop ? @Bergi – Janit Lodha Commented Apr 25, 2021 at 6:50
-
The
for(var i=0 ; i < voters.length; i++) {
and thefor(var i=0 ; i < candidates.length; i++) {
. Both of them have an unmatched open brace. – Bergi Commented Apr 25, 2021 at 11:52
2 Answers
Reset to default 4<% for(var i=0 ; i < candidates.length; i++) { %> seems your '{' wasn't closed with '}' and should be '<%}%>'
You forgot to close the for, }. it looks like <% } %>
本文标签: javascriptSyntax ErrorUnexpected Token Catch While Compiling EJSStack Overflow
版权声明:本文标题:javascript - Syntax Error : Unexpected Token Catch While Compiling EJS - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744067504a2585273.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论