因此,我正在尝试使用Express和EJS创建一个网站。但是最近,在不进行任何更改的情况下,许多错误都与EJS和标签有关。这是一个例子。
<% include partials/header %>
<h1>Landing page!</h1>
<p>Welcome to PERSCOM</p>
<% include partials/footer %>
但是我得到这个错误。
SyntaxError: Unexpected token { in G:\perscom\perscom\views\landing.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 (G:\perscom\perscom\node_modules\ejs\lib\ejs.js:618:12)
at Object.compile (G:\perscom\perscom\node_modules\ejs\lib\ejs.js:389:16)
at handleCache (G:\perscom\perscom\node_modules\ejs\lib\ejs.js:212:18)
at tryHandleCache (G:\perscom\perscom\node_modules\ejs\lib\ejs.js:251:16)
at View.exports.renderFile [as engine] (G:\perscom\perscom\node_modules\ejs\lib\ejs.js:482:10)
at View.render (G:\perscom\perscom\node_modules\express\lib\view.js:135:8)
at tryRender (G:\perscom\perscom\node_modules\express\lib\application.js:640:10)
at Function.render (G:\perscom\perscom\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (G:\perscom\perscom\node_modules\express\lib\response.js:1008:7)
at G:\perscom\perscom\routes\index.js:9:9
at Layer.handle [as handle_request] (G:\perscom\perscom\node_modules\express\lib\router\layer.js:95:5)
at next (G:\perscom\perscom\node_modules\express\lib\router\route.js:137:13)
at Route.dispatch (G:\perscom\perscom\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (G:\perscom\perscom\node_modules\express\lib\router\layer.js:95:5)
at G:\perscom\perscom\node_modules\express\lib\router\index.js:281:22
如果我删除了使用EJS标记的任何页面,也会出现类似的错误,此问题已得到解决。我该如何解决?
标题
<!DOCTYPE HTML>
<html>
<head>
<title>PERSCOM</title>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/css/bootstrap.min.css" integrity="sha384-GJzZqFGwb1QTTN6wy59ffF1BuGJpLSa9DkKMp0DgiMDm4iYMj70gZWKYbI706tWS" crossorigin="anonymous">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<a class="navbar-brand" href="/landing">PERSCOM</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav">
<li class="nav-item">
<a class="nav-link" href="/listusers">Show Members</a>
</li>
<%(currentUser) {%>
<li class="nav-item">
<a class="nav-link" href="opcenter">Operations Center</a>
</li>
<%}%>
</ul>
<ul class="navbar-nav ml-auto">
<%if(!currentUser) { %>
<li class="nav-item">
<a class="nav-link" href="/login">Login</a>
</li>
<li class="nav-item">
<a class="nav-link" href="/register">Register</a>
</li>
<% } else { %>
<span class="navbar-text">Signed in as <span style="font-weight: 800; color:black;"><%=currentUser.username%></span></span>
<li class="nav-item">
<a class="nav-link" href="/logout">Logout</a>
</li>
<% } %>
</ul>
</div>
</nav>
脚
</body>
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.6/umd/popper.min.js" integrity="sha384-wHAiFfRlMFy6i5SRaxvfOCifBUQy1xHdJ/yoi7FRNXMRBu5WHdZYu1hA6ZOblgut" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.2.1/js/bootstrap.min.js" integrity="sha384-B0UglyR+jN6CkvvICOB2joaf5I4l3gm9GU6Hc1og6Ls7i6U/mkkaduKaBhlAXv9k" crossorigin="anonymous"></script>
</html>