node.js - SynataxError:编译 ejs 文件时出现意外的标识符
问题描述
有谁知道以下错误是什么?
SyntaxError:编译 ejs 时 /home/smart/Downloads/npmPackage/views/test.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) 的 new Function () /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.在 tryRender (/home/smart/Downloads/npmPackage/node_modules/express/lib/application.js:640:10 渲染 (/home/smart/Downloads/npmPackage/node_modules/express/lib/view.js:135:8) ) 在 ServerResponse 的 Function.render (/home/smart/Downloads/npmPackage/node_modules/express/lib/application.js:592:3)。
这是我的 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>
解决方案
你必须把它用双引号括起来,让它像一个函数调用一样。你也应该使用<%-
包含回声文档
您的模板应如下所示:
<!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>
推荐阅读
- .net - 在 .NET Core 中,响应被 CORS 策略阻止,尽管我已经在使用中间件
- node.js - 尝试使用redis将数组转换为猫鼬文档时,Document()的参数obj必须是一个对象
- linux - 基于 VPN 的 Docker Swarm 集群
- java - 根据 Java 中的值重新创建 XML
- android - 在 Jetpack Compose 中管理状态
- python - 在python中查找具有5列的数组的第二个最大值
- html - 使用 href 重新加载当前页面
- javascript - 通过 ObjectId 找到的 MongoDB 在 Javascript 中不起作用
- mysql - 由于操作系统错误 105,MySQL 服务将不再启动
- powershell - 使用 Powershell 将目录路径(字符串)拆分为两个字符串