簡體   English   中英

編譯 ejs 時 /workspace/Frontend/todoApp/views/board.ejs 中出現意外標識符?

[英]Unexpected identifier in /workspace/Frontend/todoApp/views/board.ejs while compiling ejs?

運行我的代碼時遇到以下錯誤。 但是,當我將 views/board.ejs 中的包含語法更改為“<%- include('partials/header'); -%>”時,代碼就起作用了。 我認為錯誤與包含語法有關? 我很困惑,因為“<% include partials/header %>”以前為我工作過。 幫助將不勝感激,非常感謝!

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>

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

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

它不再

<% include partials/header %>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM