简体   繁体   English

语法错误:编译 EJS 时意外捕获令牌

[英]Syntax Error : Unexpected Token Catch While Compiling EJS

I am working on a project in Node.JS Express.我正在使用 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:我的 adm.ejs 文件是:

 <%- 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 inte.net regarding this error but everyone showed that there is a problem in the include syntax which is correct for me.我尝试在 inte.net 上搜索有关此错误的信息,但每个人都表明 include 语法中存在问题,这对我来说是正确的。 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谢谢

<% for(var i=0; i < candidates.length; i++) { %> seems your '{' wasn't closed with '}' and should be '<%}%>' <% for(var i=0; i < candidates.length; i++) { %> 似乎你的 '{' 没有用 '}' 结束,应该是 '<%}%>'

You forgot to close the for, }.您忘记关闭 for,}。 it looks like <% } %>它看起来像 <% } %>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM