簡體   English   中英

語法錯誤:編譯 EJS 時意外捕獲令牌

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

我正在使用 Node.JS Express 開發一個項目。 我有好幾頁都運行良好,但只有一頁(直到現在)在加載時出現錯誤。 當我運行該頁面時,彈出一個錯誤,即:

 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)

我的 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>

我嘗試在 inte.net 上搜索有關此錯誤的信息,但每個人都表明 include 語法中存在問題,這對我來說是正確的。 此外,我的此頁面的路由器文件除了將此頁面呈現給客戶端的獲取請求外別無其他。

那問題出在哪里呢?

謝謝

<% for(var i=0; i < candidates.length; i++) { %> 似乎你的 '{' 沒有用 '}' 結束,應該是 '<%}%>'

您忘記關閉 for,}。 它看起來像 <% } %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM