javascript - Syntax Error : Unexpected Token Catch While Compiling EJS - Stack Overflow

I am working on a project in Node.JS Express.I had several pages all of which are running fine but onl

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 the for(var i=0 ; i < candidates.length; i++) {. Both of them have an unmatched open brace. – Bergi Commented Apr 25, 2021 at 11:52
Add a ment  | 

2 Answers 2

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 <% } %>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744067504a4552929.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信