意外的令牌'}'在d:\ .users.ejs中编译EJ时,如果上述错误无用,则可能需要尝试EJS-lint:https://github.com/ryanzim/

发布于 2025-01-24 03:59:30 字数 3639 浏览 1 评论 0原文

这是我的控制器文件,

async function getUsers(req, res, next) {
    try {
        const users = await User.find();
        res.render('users', {
            users: users
        })
        res.render('users')

    } catch (err) {
        next(err)

    }
    // res.render('users')

}

这是我的users.ejs文件

<%- include('./partials/header.ejs'); %>
<div class="manageUser-container">
   <div id="title">
      <h2>Manage Users</h2>
   </div>
   <div class="new-message-container new-user">
      <a href="#" onclick="openModal()">+</a>
   </div>
   <div id="users-table">
      <table>
         <thead>
            <tr>
               <th>Name</th>
               <th>Email</th>
               <th>Manage</th>
            </tr>
         </thead>
         <tbody id="users-table">
            -->
            <% users.forEach((user)=>{ %>
            <tr id="<%= user._id %>">
               <td class="name">
                  <% if( user.avatar){ %>
                  <img src="./uploads/avatars/<%= user.avatar  %>" />
                  <%=}else{  %>
                  <img src="./images/nophoto.png" alt="User" />
                  <%    } %>
                  <span><%= user.name %></span>
               </td>
               <td><%= user.email %></td>
               <td class="manage">
                  <img src="./images/trash.png" alt="Delete" />
               </td>
            </tr>
            -->
            <h1>Hello</h1>
            `enter code here`
            <% }) %>
         </tbody>
      </table>
   </div>
</div>
<%- include('./partials/addUserModal.ejs'); %>
</body>
</html>

错误在浏览器中显示

  d:\ programming \ nodejs \ chat_application \ views \ tiews \ users.ejs中的意外令牌'}'在编译时
 

ejs如果上述错误无用,则可能需要尝试EJS-lint: https://github.com/ryanzim/ejs-lint 或者,如果您打算创建创建一个 异步函数,通过async:true作为选项。

SyntaxError:意外的令牌'}' D:\编程\ nodejs \ chat_application \ views \ users.ejs编译时 EJS如果以上错误无用,则可能需要尝试EJS-lint: https://github.com/ryanzim/ejs-lint 或者,如果您打算创建创建一个 异步函数,将async:true作为选项。在新功能 ()在template.com上 (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:662:12) 在object.com上 (d:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:396:16) 在handlecache (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:233:18) 在tryhandlecache (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:272:16) 在view.exports.renderfile [作为引擎] (D:\编程\ nodejs \ chat_application \ node_modules \ ejs \ lib \ ejs.js:489:10) 在View.Render (D:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ lib \ view.js:135:8) 在Tryrender (d:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ lib \ application.js:640:10) 在function.render (d:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ lib \ application.js:592:3) 在serverresponse.render上 (d:\编程\ nodejs \ chat_application \ node_modules \ express \ lib \ response.js:1017:7)

如何解决此错误?

This is my controller file

async function getUsers(req, res, next) {
    try {
        const users = await User.find();
        res.render('users', {
            users: users
        })
        res.render('users')

    } catch (err) {
        next(err)

    }
    // res.render('users')

}

this is my users.ejs file

<%- include('./partials/header.ejs'); %>
<div class="manageUser-container">
   <div id="title">
      <h2>Manage Users</h2>
   </div>
   <div class="new-message-container new-user">
      <a href="#" onclick="openModal()">+</a>
   </div>
   <div id="users-table">
      <table>
         <thead>
            <tr>
               <th>Name</th>
               <th>Email</th>
               <th>Manage</th>
            </tr>
         </thead>
         <tbody id="users-table">
            -->
            <% users.forEach((user)=>{ %>
            <tr id="<%= user._id %>">
               <td class="name">
                  <% if( user.avatar){ %>
                  <img src="./uploads/avatars/<%= user.avatar  %>" />
                  <%=}else{  %>
                  <img src="./images/nophoto.png" alt="User" />
                  <%    } %>
                  <span><%= user.name %></span>
               </td>
               <td><%= user.email %></td>
               <td class="manage">
                  <img src="./images/trash.png" alt="Delete" />
               </td>
            </tr>
            -->
            <h1>Hello</h1>
            `enter code here`
            <% }) %>
         </tbody>
      </table>
   </div>
</div>
<%- include('./partials/addUserModal.ejs'); %>
</body>
</html>

and error show in browsers

Unexpected token '}' in D:\programming\nodejs\chat_application\views\users.ejs while compiling

ejs If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint Or, if you meant to create an
async function, pass async: true as an option.

SyntaxError: Unexpected token '}' in
D:\programming\nodejs\chat_application\views\users.ejs while compiling
ejs If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint Or, if you meant to create an
async function, pass async: true as an option. at new Function
() at Template.compile
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:662:12)
at Object.compile
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:396:16)
at handleCache
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:233:18)
at tryHandleCache
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:272:16)
at View.exports.renderFile [as engine]
(D:\programming\nodejs\chat_application\node_modules\ejs\lib\ejs.js:489:10)
at View.render
(D:\programming\nodejs\chat_application\node_modules\express\lib\view.js:135:8)
at tryRender
(D:\programming\nodejs\chat_application\node_modules\express\lib\application.js:640:10)
at Function.render
(D:\programming\nodejs\chat_application\node_modules\express\lib\application.js:592:3)
at ServerResponse.render
(D:\programming\nodejs\chat_application\node_modules\express\lib\response.js:1017:7)

How can i solve this error.?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

奢望 2025-01-31 03:59:30

我可以帮助您调试此问题,但是您必须自己解决。以下步骤:

  1. 我们从错误消息中知道,它在users.ejs
  2. ,我们还知道它与}
  3. 计算机有关。

因此,此users.ejs具有几个部分视图,或include指令。要缩小问题:只需删除所有include,请查看问题是否持续? (如果需要,请重新启动服务器)

如​​果问题消失了,我们知道错误在其中一个include文件之一。

如果不是,我们继续进行步骤,通过查看任何},按行删除该服务器,重新启动服务器(只是为了确保我们获得最新的代码),请注意是否出错,请重复。

I can help you debug this issue, but you will have to resolve it yourself. Here are the steps:

  1. We know from the error message that it is inside the users.ejs
  2. And we also know that it has something to do with }
  3. Computers never lie to us.

So this users.ejs has several partial views, or include directive. To narrow down the problem: Just remove all include, see if the problem persist? (restart the server if needed)

if the problem gone, we know that the error is inside one of those include files.

If not, we continue the step, by looking at any }, remove it line by line, restart the server (just to make sure we get the latest code), watch if the error gone, repeat.

私野 2025-01-31 03:59:30

我在users.ejs文件中创建了此错误。

在这里我声明= ejs表达式中的文件如下:

<%= }else{ %>

但是解决方案是

 <% } else { %>

我在&lt;%之后删除= sign = sign&lt;%,因为如果我想打印一些值,请使用&lt; %=标志...我认为这对许多开发人员有帮助

i created this error inside the users.ejs file

Here i declared = inside the ejs expression like :

<%= }else{ %>

But the solution is

 <% } else { %>

i remove = sign after <% because else is a condition not value if i want to print some value then use <%= sign... i think it will help full for many developer

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文