编译EJS时出现SyntaxError: Unexpected Identifier问题

11

在Windows上运行应用程序时,我遇到了下面的错误。

    SyntaxError: Unexpected identifier in \path\views\landing.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 (\path\node_modules\ejs\lib\ejs.js:626:12)
    at Object.compile (\path\node_modules\ejs\lib\ejs.js:366:16)
    at handleCache (\path\node_modules\ejs\lib\ejs.js:215:18)
    at tryHandleCache (\path\node_modules\ejs\lib\ejs.js:254:16)
    at View.exports.renderFile [as engine] (\path\node_modules\ejs\lib\ejs.js:459:10)
    at View.render (\path\node_modules\express\lib\view.js:135:8)
    at tryRender (\path\node_modules\express\lib\application.js:640:10)
    at Function.render (\path\node_modules\express\lib\application.js:592:3)
    at ServerResponse.render (\path\node_modules\express\lib\response.js:1012:7)

这是我的代码片段:

<% include partials/header %>
    <h1>Landing Page</h1>
    <a href ="/campgrounds">View all campgrounds</a>
    <p>Trademark</p>    
<% include partials/footer %>
4个回答

25
<%- include('header'); -%>
<h1>
  Title
</h1>
<p>
  My page
</p>
<%- include('footer'); -%>

1
太快了!谢谢!我应该在哪里查阅有关使用<%- include('foo') -%>的指南? - svynsaenz
当我执行此操作时,出现以下错误:https://pastebin.com/yterFEKE - demiculus

12
<%- include('partials/header'); -%>
<h1>
  Title
</h1>
<p>
  My page
</p>
<%- include('partials/footer'); -%>

在使用此功能之前,您必须在主文件中使用app.set("view engine","ejs")。


3

或者

<%- include('partials/header'); %>
<h1>
  Title
</h1>
<p>
  My page
</p>
<%- include('partials/footer'); %>

3
希望这能对您有所帮助。请看下面的标签:

在此输入图片描述


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接