【问题标题】:SyntaxError: Unexpected identifier when using ejs in nodejsSyntaxError:在 nodejs 中使用 ejs 时出现意外的标识符
【发布时间】:2019-12-31 01:04:30
【问题描述】:

我在 youtube 上关注 The Net Nijna 的教程。 我达到了第 27 个教程,在 ejs 中使用 partials。一切正常,直到我添加 ,一旦我添加了这个代码,我就会收到:

SyntaxError: Unexpected identifier in (file location) testapp\views\profile.ejs 同时编译 ejs

如果上述错误没有帮助,您可能想尝试 EJS-Lint: https://github.com/RyanZim/EJS-Lint 或者,如果您打算创建一个异步函数,请将 async: true 作为选项传递。 在 new Function () ..... 等等等等......

如果我删除它,我的 ejs 一切正常。

  <body>
    <% include partials/nav.ejs %>

    <h1>Welcome to the profile of <%= person %> !</h1>
    <p><strong> Age: <%= data.age %></strong></p>

    <p><strong> Job: <%= data.job %></strong></p>
    <p><strong> Pet: <%= data.pet %></strong></p>
    <h2>Hobbies</h2>
    <ul>
      <% data.hobbies.forEach(function(item){ %>
        <li><%= item %></li>
      <%});%>
    </ul>
  </body>

你能帮助一个学生吗?非常感谢!

【问题讨论】:

  • 试试 或
  • 试过第二个,没用,但你的第一个成功了!砰!非常感谢!
  • 不客气

标签: node.js ejs


【解决方案1】:

缺少连字符,需要调用包含函数。

 <%- include('partials/nav') %>

【讨论】:

  • 对于 Evan Hahn 的 Express in Action 的读者,这修复了第 3 章示例应用程序代码中的错误。感谢 Joseph!
【解决方案2】:

我遇到了同样的问题并使用了-include('#filename'); 成功了

【讨论】:

    【解决方案3】:

    使用:

    • 同意@Joseph Varilla
    • 不需要包含引擎扩展,因为这应该在 app.js 或 index.js 文件中完成

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-05-15
      • 1970-01-01
      • 2012-12-27
      • 2018-07-19
      • 2018-03-01
      • 2019-10-28
      • 2020-03-24
      相关资源
      最近更新 更多