SyntaxError:nodejs 中出现意外的令牌错误

时间:2021-04-30 10:10:50

标签: node.js error-handling syntax token ejs

我刚开始学习 Node JS。渲染 ejs 文件时,出现意外令牌错误。任何人 帮我解决这个错误。

Error: 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 (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/ejs/lib/ejs.js:661:12)
    at Object.compile (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/ejs/lib/ejs.js:396:16)
    at handleCache (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/ejs/lib/ejs.js:233:18)
    at tryHandleCache (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/ejs/lib/ejs.js:272:16)
    at View.exports.renderFile [as engine] (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/ejs/lib/ejs.js:489:10)
    at View.render (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/view.js:135:8)
    at tryRender (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/application.js:640:10)
    at Function.render (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/response.js:1012:7)
    at ServerResponse.res.render (/root/iacs-crud-hbs/iacs-crud-hbs/argon-dashboard-nodejs/node_modules/express-ejs-layouts/lib/express-layouts.js:77:18)
    at loadPage (/root/iacs-crud-hbs/iacs-crud-hbs/argon-dashboard-nodejs/features/login/commands/load-page.js:5:7)
    at /root/iacs-crud-hbs/iacs-crud-hbs/argon-dashboard-nodejs/node_modules/async-middleware/dist/index.js:18:23
    at Layer.handle [as handle_request] (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/layer.js:95:5)
    at next (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/layer.js:95:5)
    at /root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/index.js:281:22
    at Function.process_params (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/index.js:335:12)
    at next (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/index.js:275:10)
    at Function.handle (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/index.js:174:3)
    at router (/root/iacs-crud-hbs/iacs-crud-hbs/node_modules/express/lib/router/index.js:47:12)

我的代码如下:

<body class="bg-default">
  <div class="main-content">
    <!-- Navbar -->
    <% include ../partials/auth/navbar %>
    <!-- Header -->
    <% include ../partials/auth/header %>
    <!-- Page content -->
    <div class="container mt--8 pb-5">
      <div class="row justify-content-center">
        <div class="col-lg-5 col-md-7">
          <div class="card bg-secondary shadow border-0">
            <div class="card-header bg-transparent pb-5">
              <div class="text-muted text-center mt-2 mb-3"><small>Sign in with</small></div>
              <div class="btn-wrapper text-center">
                <a href="#" class="btn btn-neutral btn-icon">
                  <span class="btn-inner--icon"><img src="img/icons/common/github.svg"></span>
                  <span class="btn-inner--text">Github</span>
                </a>
                <a href="#" class="btn btn-neutral btn-icon">
                  <span class="btn-inner--icon"><img src="img/icons/common/google.svg"></span>
                  <span class="btn-inner--text">Google</span>
                </a>
              </div>
            </div>
            <div class="card-body px-lg-5 py-lg-5">
              <div class="text-center text-muted mb-4">
                <small>Or sign in with credentials</small>
                <br />
                <small>
                  You can use <strong>admin@argon.com</strong> and <strong>secret</strong> to login
                </small>
              </div>
              <% if (locals.messages && messages.success) { %>
                <div class="mb-3">
                  <small class="text-success font-weight-700"><%= messages.success %></small>
                </div>
              <% } %>
              <form role="form" action="/login" method="POST">
                <% if (locals.messages && messages.errors && messages.errors.databaseError) { %>
                  <div class="alert alert-danger alert-dismissible fade show" role="alert">
                    <%= messages.errors.databaseError %>
                    <button type="button" class="close" data-dismiss="alert" aria-label="Close">
                      <span aria-hidden="true">×</span>
                    </button>
                  </div>
                <% } %>
                <div class="form-group mb-3">
                  <div class="input-group input-group-alternative">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="ni ni-email-83"></i></span>
                    </div>
                    <input class="form-control" placeholder="Email" type="email" name="username">
                  </div>
                  <% if (locals.messages && messages.errors) { %>
                    <% Object.keys(messages.errors).filter(function(key) { return ['username', 'invalidEmailOrPassword', 'internalServerError'].includes(key); }).map(function(key) { %>
                      <strong class="invalid-feedback" style="display: block">
                        <%= messages.errors[key] %>
                      </strong>
                    <% }) %>
                  <% } %>
                </div>
                <div class="form-group">
                  <div class="input-group input-group-alternative">
                    <div class="input-group-prepend">
                      <span class="input-group-text"><i class="ni ni-lock-circle-open"></i></span>
                    </div>
                    <input class="form-control" placeholder="Password" type="password" name="password">
                  </div>
                  <% if (locals.messages && messages.errors && messages.errors.password) { %>
                    <strong class="invalid-feedback" style="display: block">
                      <%= messages.errors.password %>
                    </strong>
                  <% } %>
                </div>
                <div class="custom-control custom-control-alternative custom-checkbox">
                  <input class="custom-control-input" id=" customCheckLogin" type="checkbox">
                  <label class="custom-control-label" for=" customCheckLogin">
                    <span class="text-muted">Remember me</span>
                  </label>
                </div>
                <div class="text-center">
                  <button class="btn btn-primary my-4">Sign in</button>
                </div>
              </form>
            </div>
          </div>
          <div class="row mt-3">
            <div class="col-6">
              <a href="/reset-password" class="text-light"><small>Forgot password?</small></a>
            </div>
            <div class="col-6 text-right">
              <a href="/register" class="text-light"><small>Create new account</small></a>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  <!-- Footer -->
  <% include ../partials/auth/footer %>

  <!-- Include scripts -->
  <% include ../partials/scripts %>
</body>

1 个答案:

答案 0 :(得分:0)

您的 include 语法错误。请参阅 docs 中的包含部分。您需要将路径名用引号和括号括起来:

<% include ../partials/auth/navbar %>

更改为:

<% include("../partials/auth/navbar") %>