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的一个选项,但是我在运行它时遇到了一个奇怪的错误。
发布于 2021-01-02 00:34:12
昨天我无法完全测试您的代码,因为我正在移动。
这个问题实际上来自于=在<%=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>
          <% }) %>这应该可以排除错误。
https://stackoverflow.com/questions/65530175
复制相似问题