我在运行代码时遇到以下错误。但是,当我将views / board.ejs中的include语法更改为“ <%-include('partials / header');-%>”时,代码起作用了。我认为该错误与include语法有关?我很困惑,因为“ <%包括部分/标题%>”以前为我工作过。非常感谢您的帮助,非常感谢!
SyntaxError: Unexpected identifier in /workspace/Frontend/todoApp/views/board.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 (/workspace/Frontend/todoApp/node_modules/ejs/lib/ejs.js:626:12)
at Object.compile (/workspace/Frontend/todoApp/node_modules/ejs/lib/ejs.js:366:16)
at handleCache (/workspace/Frontend/todoApp/node_modules/ejs/lib/ejs.js:215:18)
at tryHandleCache (/workspace/Frontend/todoApp/node_modules/ejs/lib/ejs.js:254:16)
at View.exports.renderFile [as engine] (/workspace/Frontend/todoApp/node_modules/ejs/lib/ejs.js:459:10)
at View.render (/workspace/Frontend/todoApp/node_modules/express/lib/view.js:135:8)
at tryRender (/workspace/Frontend/todoApp/node_modules/express/lib/application.js:640:10)
at Function.render (/workspace/Frontend/todoApp/node_modules/express/lib/application.js:592:3)
at ServerResponse.render (/workspace/Frontend/todoApp/node_modules/express/lib/response.js:1012:7)
at /workspace/Frontend/todoApp/app.js:16:6
at Layer.handle [as handle_request] (/workspace/Frontend/todoApp/node_modules/express/lib/router/layer.js:95:5)
at next (/workspace/Frontend/todoApp/node_modules/express/lib/router/route.js:137:13)
at Route.dispatch (/workspace/Frontend/todoApp/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/workspace/Frontend/todoApp/node_modules/express/lib/router/layer.js:95:5)
at /workspace/Frontend/todoApp/node_modules/express/lib/router/index.js:281:22
这是我的代码段:
// app.js
var express = require("express"),
app = express(),
bodyParser = require("body-parser"),
mongoose = require("mongoose"),
flash = require("connect-flash"),
methodOverride = require("method-override");
mongoose.connect("mongodb://localhost/test", {
useNewUrlParser: true,
useUnifiedTopology: true
})
app.set("view engine", "ejs")
app.get("/", function(req, res){
res.render("board");
})
app.get("/board", function(req, res){
res.send("This will be the board page!")
})
app.listen(3000, function(){
console.log("Server listening on port 3000");
})
<!-- views/board.ejs -->
<% include partials/header %>
<h1>
This is the board page.
</h1>
<% include partials/footer %>
<!-- views/partials/header.ejs -->
<!DOCTYPE html>
<html>
<head>
<title>Todo App</title>
</head>
<body>
<!-- views/partials/footer.ejs -->
<!-- jQuery CDN -->
<script
src="https://code.jquery.com/jquery-3.1.1.min.js"
integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8="
crossorigin="anonymous"></script>
<!-- Bootstrap JS CDN -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
</body>
</html>
答案 0 :(得分:0)
EJS最近已更新到v3.0.1,现在使用以下语法:
self._get_non_slot_variable("beta1_power", graph=graph)
不再了
<%- include("partials/header") %>
<%- include("partials/footer") %>