我正在尝试执行一个简单的 EJS 程序,但在编译 EJS 时出现意外令牌 ')' 错误

I am Trying to execute a simple EJS program, But getting Unexpected Token ')' error while compiling EJS

我将在这里展示我的代码:这是一个非常简单的代码,只显示工作日或周末。 从 NPM 安装程序安装 EJS 包

这是 list.ejs(在 views 文件夹内)

    <!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>T Do List</title>
    <script src="app.js"></script>
</head>
<body>
    <!-- The EJS is represented by <%= EJS =%> -->
   <h1>It is a <%= kindOfDay =%> !</h1> <!-- Corrected -->
</body>
</html>

这是app.js

const express = require("express");
    const bodyParser = require("body-parser");
    
    const app = express();
    
    app.set('view engine','ejs'); //for EJS
    
    
    app.get("/", function(req, res){
    
        var today = new Date();
        var currentDay = today.getDay();
        var day = "";
    
        if(currentDay === 6 || currentDay === 0) // Sunday - Saturday : 0:6
        {
            day = "weekend";
             // list has to exist in views folder || EJS keyword has to match the {key: value} pair
    
        }
        else {
            day = "weekday";
            
        }
    
        res.render("list", {kindOfDay: day}); 
    });
    
    app.listen(3000, function(){
        console.log("Server running at port 3000");
    })

这是 index.html 文件

这是我遇到的错误:

SyntaxError: Unexpected token ')' in ..\todoList-v1\views\list.ejs while compiling ejs

If the above error is not helpful, you may want to try EJS-Lint:
https://github.com/RyanZim/EJS-Lint
Or, if you meant to create an async function, pass `async: true` as an option.
    at new Function (<anonymous>)
    at Template.compile (..\todoList-v1\node_modules\ejs\lib\ejs.js:662:12)
   

任何帮助将不胜感激:谢谢

tag 的正确语法是 - <%= 并且应该以 %> 结尾。您在两边都添加了 =。请从结束标记中删除。应该是 -

<h1>It is a <%= kindOfDay %> !</h1>

此外,您在 Ejs 中添加评论的方式不正确。

<!-- The EJS is represented by <%= EJS =%> -->

这条评论正在执行中。请阅读 this 问题关于在 Ejs 中添加评论的回答。如链接问题的答案中所述,您应该使用 <%# comment %> 作为评论。

最后,如果您试图在 Ejs 中包含主 app.js 文件,则不要这样做。 Ejs 都是关于前端的部分。因此,您应该包括在浏览器中运行的脚本。