SynataxError:编译 ejs 文件时出现意外标识符

Dik*_*yal 5 ejs node.js

有谁知道以下错误是什么?

语法错误:编译 ejs 时 /home/smart/Downloads/npmPackage/views/test.ejs 中出现意外标识符

如果上述错误没有帮助,您可能想尝试 EJS-Lint:https : //github.com/RyanZim/EJS-Lint或者,如果您打算创建一个异步函数,请通过async: true作为一种选择。在新函数 () at Template.compile (/home/smart/Downloads/npmPackage/node_modules/ejs/lib/ejs.js:626:12) at Object.compile (/home/smart/Downloads/npmPackage/node_modules/ejs /lib/ejs.js:366:16) 在 handleCache (/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。渲染 (/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。

这是我的 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>
Run Code Online (Sandbox Code Playgroud)

mam*_*man 7

你必须把它放在双引号里,就像函数调用一样。你也应该使用<%-包含回声文档

您的模板应如下所示:

<!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>
Run Code Online (Sandbox Code Playgroud)