【发布时间】:2021-04-21 21:14:03
【问题描述】:
我正在尝试使用 html 和 nodejs 构建网页。我在html代码的某些地方使用了ejs。运行服务器时出现以下错误。虽然我已经为每个“
Error: Could not find matching close tag for "<%".
at C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:739:19
at Array.forEach (<anonymous>)
at Template.generateSource (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:729:15)
at Template.compile (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:583:12)
at Object.compile (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:396:16)
at handleCache (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:233:18)
at tryHandleCache (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:272:16)
at View.exports.renderFile [as engine] (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\ejs\lib\ejs.js:489:10)
at View.render (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\express\lib\view.js:135:8)
at tryRender (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\express\lib\application.js:640:10)
at Function.render (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\express\lib\application.js:592:3)
at ServerResponse.render (C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\node_modules\express\lib\response.js:1012:7)
at C:\Users\GANDHARAV\OneDrive\Desktop\nodejs\first_app\server.js:19:7
at processTicksAndRejections (internal/process/task_queues.js:93:5)
以下是我的html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<meta http-equiv="X-UA-Comaptible" content="ie=edge">
<title>Blog</title>
</head>
<body>
<div class="container">
<h1 class="mb-4">Blog Articles</h1>
<a href="/articles/new" class="btn btn-succeess">New Article</a>
<% articles.forEach(article = > { %>
<div class="card mt-4">
<div class="card-body">
<h4 class="card-title"><%= article.title %></h4>
<div class="card-subtitle tetxt-muted mb-2">
<%= article.createdAt.toLocalDateString() %>
</div>
<div class="card-text mb-2"><%= article.description %></div>
<a href="articles/<%= article.slug %>" class="btn btn-primary"> Read more </a>
<a href="articles/edit/<%= article.id %>" class="btn btn-info"> Edit </a>
<form action="/articles/<%= article.id %>?_method=DELETE" method="POST" class="d-inline">
<button type="submit" class="btn btn-danger">Delete</button>
</form>
</div>
</div>
<% }) >
</div>
</body>
</html>
**我已经安装了以下依赖项:**
{
"name": "first_app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies": {
"dompurify": "^2.2.6",
"ejs": "^3.1.5",
"express": "^4.17.1",
"jsdom": "^16.4.0",
"marked": "^1.2.7",
"method-override": "^3.0.0",
"mongoose": "^5.11.12",
"nodemon": "^2.0.7",
"slugify": "^1.4.6"
}
}
从下图中,VS 代码似乎无法识别 ejs 代码。因为无论我从 "
【问题讨论】:
-
这个问题应该被关闭,因为它是由一个错字引起的。
标签: javascript html node.js express ejs