【问题标题】:SynataxError: Unexpected Indentifier while compiling ejs fileSyntaxError:编译 ejs 文件时出现意外的标识符
【发布时间】:2020-05-15 16:57:06
【问题描述】:

有谁知道下面的错误是什么原因?

SyntaxError: 中的意外标识符 /home/smart/Downloads/npmPackage/views/test.ejs 同时编译ejs

如果上述错误没有帮助,您可能想尝试 EJS-Lint: https://github.com/RyanZim/EJS-Lint 或者,如果您打算创建一个 async 函数,传递async: true 作为选项。 在新函数 () 在 Template.compile (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:626:12) 在 Object.compile (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:366:16) 在句柄缓存(/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:215:18) 在 tryHandleCache (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:254:16) 在 View.exports.renderFile [作为引擎] (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:459:10) 在 View.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/view.js:135:8) 在 tryRender (/home/smart/Downloads/npmPackage/node_modules/express/lib/application.js:640:10) 在 Function.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/application.js:592:3) 在 ServerResponse.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/response.js:1012:7) SyntaxError:意外的标识符 /home/smart/Downloads/npmPackage/views/test.ejs 同时编译ejs

这是我的 ejs 文件

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
        <% include partials/navbar %>
    <h1>This is a test Page</h1>
</body>
</html>

【问题讨论】:

    标签: node.js ejs


    【解决方案1】:

    你必须用双引号把它放在一个函数调用中。你也应该使用 &lt;%- 包含 echo documentation

    您的模板应如下所示:

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta http-equiv="X-UA-Compatible" content="ie=edge">
        <title>Document</title>
    </head>
    <body>
            <%- include("./partials/navbar") %>
        <h1>This is a test Page</h1>
    </body>
    </html>
    

    【讨论】:

    • 感谢您的帮助,但我不明白为什么我必须更改此格式,因为我在所有其他项目中一直使用该格式并且它们运行良好。跨度>
    • @DikshaGoyal,我认为这是一个遗留包含,它已从最新更新中删除,检查更改日志:github.com/mde/ejs/blob/master/CHANGELOG.md
    • 哦,是的.. 非常感谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-03-24
    • 1970-01-01
    • 2019-10-28
    • 1970-01-01
    • 2020-03-22
    • 2021-10-13
    相关资源
    最近更新 更多