Home > Net >  Could not find matching close tag for "<%" in node_modules/ejs/lib/ejs.js for Array.for
Could not find matching close tag for "<%" in node_modules/ejs/lib/ejs.js for Array.for

Time:05-04

I new to node and mongoDB and here I am trying to build a to-do-list. My project folder beautiful-todolist_mongoDB has a views folder containing list.ejs and other .ejs files.

Error : Could not find matching close tag for "<%". at /Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:740:19 at Array.forEach () at Template.generateSource (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:730:15) at Template.compile (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:585:12) at Object.compile (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:396:16) at handleCache (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:233:18) at tryHandleCache (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:272:16) at View.exports.renderFile [as engine] (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:489:10) at View.render (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/express/lib/view.js:135:8) at tryRender (/Users/xxx/Documents/beautiful-todolist_mongoDB/node_modules/express/lib/application.js:640:10)

My list.ejs


<%- include("header") -%>
<div  id="heading">
  <h1><%=listTitle%></h1>
</div>

<div >
  <!-- <% for (var i=0; i<listItems.length ; i  ) { %>
          <div >
            <input type="checkbox">
            <p><%= listItems[i].name %></p>
          </div>
          <% } %> -->
  <% listItems.forEach(function(item){ %>
  <div >
    <input type="checkbox" />
    <p><%= item.name %></p>
  </div>
  <% }) %>
  <form  action="/" method="post">
    <input
      type="text"
      name="task"
      id="task"
      placeholder="New Item"
      autocomplete="off"
    />
    <button type="submit" name="list" value="<%" ="listTitle%">> </button>
  </form>
</div>
<%- include("footer") -%>


I don't understand why it shows that I have a missing closing tag for <%. The same code is working when I use the for loop but forEach is not working. Also, I tried reading the error and looking for the root cause but it does not say if I have an error in beautiful-todolist_mongoDB/node_modules/views/list.ejs rather it says I have a missing closing tag in beautiful-todolist_mongoDB/node_modules/ejs/lib/ejs.js:740:19

CodePudding user response:

There's a typo at your button:

<button type="submit" name="list" value="<%" ="listTitle%">> </button>

You are not closing the ejs tags here. It should be like this:

<button type="submit" name="list" value="<%= listTitle %>"> </button>
  • Related