为了账号安全,请及时绑定邮箱和手机立即绑定

SyntaxError: Unexpected token || 在 /var/www/html/v

SyntaxError: Unexpected token || 在 /var/www/html/v

泛舟湖上清波郎朗 2022-05-22 11:04:30
我正在尝试从他在 Udemy 上的 Web Dev Bootcamp 构建类似于 Colt Steele 的 YelpCamp 项目的东西。我的项目一直进行到课程结束时使用提供的 YouTube 材料进行重构。我收到以下错误消息,试图显示数据库中的任何内容:SyntaxError: Unexpected token || in /var/www/html/views/components/show.ejs while compiling ejsIf the above error is not helpful, you may want to try EJS-Lint:https://github.com/RyanZim/EJS-LintOr, if you meant to create an async function, pass `async: true` as an option.    at new Function (<anonymous>)    at Template.compile (/var/www/html/node_modules/ejs/lib/ejs.js:626:12)    at Object.compile (/var/www/html/node_modules/ejs/lib/ejs.js:366:16)    at handleCache (/var/www/html/node_modules/ejs/lib/ejs.js:215:18)    at tryHandleCache (/var/www/html/node_modules/ejs/lib/ejs.js:254:16)    at View.exports.renderFile [as engine] (/var/www/html/node_modules/ejs/lib/ejs.js:459:10)    at View.render (/var/www/html/node_modules/express/lib/view.js:135:8)    at tryRender (/var/www/html/node_modules/express/lib/application.js:640:10)    at Function.render (/var/www/html/node_modules/express/lib/application.js:592:3)    at ServerResponse.render (/var/www/html/node_modules/express/lib/response.js:1012:7)    at /var/www/html/routes/components.js:84:17    at /var/www/html/node_modules/mongoose/lib/model.js:4834:16    at /var/www/html/node_modules/mongoose/lib/helpers/promiseOrCallback.js:24:16    at /var/www/html/node_modules/mongoose/lib/model.js:4857:21    at _hooks.execPost (/var/www/html/node_modules/mongoose/lib/query.js:4366:11)    at /var/www/html/node_modules/kareem/index.js:135:16我的 /components/show(基本上是 campgrounds/show)代码如下所示:<%- include ("../partials/header") %><title><%=component.name%></title><%- include ("../partials/nav") %>  <div class="row">    <div class="col-md-3">      <p class="lead">PC Part Inventory</p>      <div class="list-group">        <li class="list-group-item active">Info 1</li>        <li class="list-group-item">Info 2</li>        <li class="list-group-item">Info 3</li>      </div>    </div>
查看完整描述

1 回答

?
明月笑刀无情

TA贡献1828条经验 获得超4个赞

在第 45 行,调用后有一个额外的右括号comment.author.id.equals(currentUser._id)。


<% if(currentUser && comment.author.id.equals(currentUser._id)) || currentUser && currentUser.isAdmin){ %>

  <!--                                                      ^^^^             -->

  <a class="btn btn-xs btn-warning"

    href="/components/<%= component._id %>/comments/<%= comment._id %>/edit">Edit</a>

  <form class="delete-form" action="/components/<%= component._id %>/comments/<%= comment._id %>?_method=DELETE" method="post">

    <input type="submit" class="btn btn-xs btn-danger" value="Delete">

  </form>

</div>

<% } %>

错误消息还建议使用ejs-lint来获取更多有用的错误消息。我建议尝试一下。在这种情况下,它打印:


Unexpected token (45:81) in test.ejs


查看完整回答
反对 回复 2022-05-22
  • 1 回答
  • 0 关注
  • 281 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号