有人知道以下错误是什么原因吗?
SyntaxError:中的意外标识符/home/smart/Downloads/npmPackage/views/test.ejs,同时编译ejs
如果以上错误没有帮助,您可以尝试使用EJS-Lint:https://github.com/RyanZim/EJS-Lint或者,如果您要创建一个异步功能,将
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)在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.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)语法错误:中的意外标识符/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>
您的模板应该看起来像这样,您已将其放在带有双qoute的位置,并且像函数调用一样。并将<%-
用于包含回显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>