编译 ejs 代码时出现 EJS 语法错误

EJS syntax error while compiling ejs code

    SyntaxError: Unexpected token ')' in C:\Users\hp\short.nner\views\index.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
    at new AsyncFunction (<anonymous>)
    at Template.compile (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:661:12)
    at Object.compile (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:396:16)
    at handleCache (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:233:18)
    at tryHandleCache (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:272:16)
    at View.exports.renderFile [as engine] (C:\Users\hp\short.nner\node_modules\ejs\lib\ejs.js:489:10)
    at View.render (C:\Users\hp\short.nner\node_modules\express\lib\view.js:135:8)
    at tryRender (C:\Users\hp\short.nner\node_modules\express\lib\application.js:640:10)
    at Function.render (C:\Users\hp\short.nner\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (C:\Users\hp\short.nner\node_modules\express\lib\response.js:1012:7)
    at C:\Users\hp\short.nner\server.js:49:17
    at processTicksAndRejections (node:internal/process/task_queues:93:5)

这是我的代码:

    <%=Url.forEach(shortUrl => { %>
                    <tr>
                        <td>
                            <a href="<%= shortUrl.full %>">
                                <%= shortUrl.full %>
                            </a>
                        </td>
                        <td>
                            <a href="<%= shortUrl.short %>">localhost:3000/<%= shortUrl.short %></a
              >
            </td>
            <td><%= shortUrl.clicks %></td>
            <td><%= shortUrl.GivenEmail %>
          </tr>
          <% }) %>

我真的不知道为什么会出现这个错误,请帮忙。 我确实将 Url 作为我的 ejs 的一个选项,但我在 运行 上遇到了这个奇怪的错误。

由于我在移动设备上,我昨天无法完全测试您的代码。

问题其实出在<%=Url.forEach(shortUrl =>开头的=。像这样删除它应该有效:

 <% Url.forEach(shortUrl => { %>
                    <tr>
                        <td>
                            <a href="<%= shortUrl.full %>">
                                <%= shortUrl.full %>
                            </a>
                        </td>
                        <td>
                            <a href="<%= shortUrl.short %>">localhost:3000/<%= shortUrl.short %></a
              >
            </td>
            <td><%= shortUrl.clicks %></td>
            <td><%= shortUrl.GivenEmail %>
          </tr>
          <% }) %>

这应该消除错误。