猿问

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

我正在尝试从他在 Udemy 上的 Web Dev Bootcamp 构建类似于 Colt Steele 的 YelpCamp 项目的东西。我的项目一直进行到课程结束时使用提供的 YouTube 材料进行重构。我收到以下错误消息,试图显示数据库中的任何内容:


SyntaxError: Unexpected token || in /var/www/html/views/components/show.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 (<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>



泛舟湖上清波郎朗
浏览 282回答 1
1回答

明月笑刀无情

在第 45 行,调用后有一个额外的右括号comment.author.id.equals(currentUser._id)。<% if(currentUser && comment.author.id.equals(currentUser._id)) || currentUser && currentUser.isAdmin){ %>&nbsp; <!--&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ^^^^&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;-->&nbsp; <a class="btn btn-xs btn-warning"&nbsp; &nbsp; href="/components/<%= component._id %>/comments/<%= comment._id %>/edit">Edit</a>&nbsp; <form class="delete-form" action="/components/<%= component._id %>/comments/<%= comment._id %>?_method=DELETE" method="post">&nbsp; &nbsp; <input type="submit" class="btn btn-xs btn-danger" value="Delete">&nbsp; </form></div><% } %>错误消息还建议使用ejs-lint来获取更多有用的错误消息。我建议尝试一下。在这种情况下,它打印:Unexpected token (45:81) in test.ejs
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答