'Syntax Error : Unexpected Token Catch While Compiling EJS
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 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, pass async: true as an option.
at new Function (<anonymous>)
at Template.compile (E:\Submit\Fresh\nodeapp\node_modules\ejs\lib\ejs.js:633:12)
at Object.compile (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
Solution 1:[1]
You forgot to close the for, }. it looks like <% } %>
Solution 2:[2]
<% for(var i=0 ; i < candidates.length; i++) { %> seems your '{' wasn't closed with '}' and should be '<%}%>'
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gerry |
| Solution 2 | Emmanuel Joseph |
