【问题标题】:Unexpected identifier in /workspace/Frontend/todoApp/views/board.ejs while compiling ejs?编译 ejs 时 /workspace/Frontend/todoApp/views/board.ejs 中出现意外的标识符?
【发布时间】:2019-12-14 00:30:20
【问题描述】:

我在运行我的代码时遇到了以下错误。但是,当我将views/board.ejs 中的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

这是我的代码 sn-p:

// 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>

【问题讨论】:

    标签: javascript html node.js ejs


    【解决方案1】:

    EJS 最近更新到 v3.0.1,现在使用以下语法:

    <%- include("partials/header") %>
    <%- include("partials/footer") %>
    

    没有了

    <% include partials/header %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 2022-10-21
      • 1970-01-01
      • 2020-03-24
      • 2021-10-13
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多