Could not find matching close tag for "<%" in node_modules/ejs/lib/ejs.js for Array.foreach()

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 class="box" id="heading">

<div class="box">
  <!-- <% for (var i=0; i<listItems.length ; i++) { %>
          <div class="item">
            <input type="checkbox">
            <p><%= listItems[i].name %></p>
          <% } %> -->
  <% listItems.forEach(function(item){ %>
  <div class="item">
    <input type="checkbox" />
    <p><%= %></p>
  <% }) %>
  <form class="item" action="/" method="post">
      placeholder="New Item"
    <button type="submit" name="list" value="<%" ="listTitle%">>+</button>
<%- 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

>Solution :

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>

Leave a Reply