Node.js EJS意外令牌/-使用部分

Node.js EJS意外令牌/-使用部分,node.js,ejs,partials,Node.js,Ejs,Partials,我试图在我的web应用程序中使用partials,但在仪表板页面上,出现以下错误: SyntaxError: Unexpected token / in /Users/ng235/Documents/Work/app-1/views/dashboard.ejs while compiling ejs If the above error is not helpful, you may want to try EJS-Lint: https://Work.com/RyanZim/EJS-Lint

我试图在我的web应用程序中使用partials,但在仪表板页面上,出现以下错误:

SyntaxError: Unexpected token / in /Users/ng235/Documents/Work/app-1/views/dashboard.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://Work.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 (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:626:12)
    at Object.compile (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:366:16)
    at handleCache (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:215:18)
    at tryHandleCache (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:254:16)
    at View.exports.renderFile [as engine] (/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:459:10)
    at View.render (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/view.js:135:8)
    at tryRender (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/application.js:640:10)
    at Function.render (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/application.js:592:3)
    at ServerResponse.render (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/response.js:1012:7)
    at /Users/ng235/Documents/Work/app-1/app.js:51:9
    at Layer.handle [as handle_request] (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/layer.js:95:5)
    at next (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/route.js:137:13)
    at Route.dispatch (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/route.js:112:3)
    at Layer.handle [as handle_request] (/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/layer.js:95:5)
    at /Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/index.js:281:22
SyntaxError:编译ejs时出现意外的令牌/in/Users/ng235/Documents/Work/app-1/views/dashboard.ejs
如果上述错误没有帮助,您可能希望尝试EJS Lint:
https://Work.com/RyanZim/EJS-Lint
或者,如果要创建异步函数,请将'async:true'作为选项传递。
在新函数()处
在Template.compile(/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:626:12)
在Object.compile(/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:366:16)
在handleCache(/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:215:18)
在tryHandleCache(/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:254:16)
在View.exports.renderFile[作为引擎](/Users/ng235/Documents/Work/app-1/node_modules/ejs/lib/ejs.js:459:10)
在View.render(/Users/ng235/Documents/Work/app-1/node_modules/express/lib/View.js:135:8)
在tryRender(/Users/ng235/Documents/Work/app-1/node_modules/express/lib/application.js:640:10)
在Function.render(/Users/ng235/Documents/Work/app-1/node_modules/express/lib/application.js:592:3)
在ServerResponse.render(/Users/ng235/Documents/Work/app-1/node_modules/express/lib/response.js:1012:7)
at/Users/ng235/Documents/Work/app-1/app.js:51:9
在Layer.handle[作为handle_请求](/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/Layer.js:95:5)
接下来(/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/route.js:137:13)
在Route.dispatch(/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/Route.js:112:3)
在Layer.handle[作为handle_请求](/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/Layer.js:95:5)
at/Users/ng235/Documents/Work/app-1/node_modules/express/lib/router/index.js:281:22
我包含我的部分的方式是:

<% include ./partials/messages %>

我的文件系统是app-2->views->partials->messages.ejs

该文件是:

<% if (message && message.length > 0) { %>
<div class="alert alert-primary my-5"><%= message %></div>
<% } %>
0){%>
我的仪表板页面(我正在尝试添加部分内容的页面)是(没有尝试泄漏任何内容):


仪表板

感谢您的帮助。

EJS现在有了一种不同的语法,用于从版本
3.x.x

替换为

新语法是:


谢谢。

请参阅下面我的答案,其中详细介绍了EJS现在如何使用不同的语法。谢谢
<div class="container text-center">
    <h1 class="display-4 my-5">Dashboard</h1>

    <% include ./partials/messages %>
</div>