EJS 意外的令牌 / - 使用部分
EJS Unexpected token / - Using 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
我包含偏音的方式是:
<% include ./partials/messages %>
我的文件系统是 app-2 -> views -> partials -> messages.ejs
那个文件是:
<% if (message && message.length > 0) { %>
<div class="alert alert-primary my-5"><%= message %></div>
<% } %>
我的仪表板页面(我试图将部分添加到的页面)是(没有试图泄漏任何东西):
<div class="container text-center">
<h1 class="display-4 my-5">Dashboard</h1>
<% include ./partials/messages %>
</div>
感谢您的帮助。
从版本 3.x.x
开始,EJS 现在对局部语法有不同的语法
将<%- include ./partials/file %>
或<% include ./partials/file %>
替换为<%- include('./partials/file') %>
新语法是:
<%- include('./partials/file') %>
谢谢。
我正尝试在我的网络应用程序中使用部分组件,但在仪表板页面上,我收到以下错误:
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
我包含偏音的方式是:
<% include ./partials/messages %>
我的文件系统是 app-2 -> views -> partials -> messages.ejs
那个文件是:
<% if (message && message.length > 0) { %>
<div class="alert alert-primary my-5"><%= message %></div>
<% } %>
我的仪表板页面(我试图将部分添加到的页面)是(没有试图泄漏任何东西):
<div class="container text-center">
<h1 class="display-4 my-5">Dashboard</h1>
<% include ./partials/messages %>
</div>
感谢您的帮助。
从版本 3.x.x
将<%- include ./partials/file %>
或<% include ./partials/file %>
替换为<%- include('./partials/file') %>
新语法是:
<%- include('./partials/file') %>
谢谢。