Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTML comment with an embedded EJS scriptlet [<% ... %>] causing error:[SyntaxError: Unexpected token '.' in __dirname+\views\list.ejs while compiling ejs] #734

Closed
RahulYavvari opened this issue May 26, 2023 · 1 comment

Comments

@RahulYavvari
Copy link

This is the package.json file
{
"name": "todo-list-v1",
"version": "1.0.0",
"description": "",
"main": "app.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Rahul",
"license": "ISC",
"dependencies": {
"body-parser": "^1.20.2",
"ejs": "^3.1.9",
"express": "^4.18.2"
}
}

With this HTML comment <!-- [<% .. %>] - is called a Scriptlet tag --> line in my list.ejs file in the views folder of project's root directory, when trying to run my server with nodemon app.js, it starts listening on the port 3000, then when trying to load localhost:3000, I am getting an error saying

-------------### [ERROR MESSAGE STARTS HERE]--------------

SyntaxError: Unexpected token '.' in {__dirname}\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 ()
at Template.compile ({__dirname}\node_modules\ejs\lib\ejs.js:673:12)
at Object.compile ({__dirname}\node_modules\ejs\lib\ejs.js:398:16)
at handleCache ({__dirname}\node_modules\ejs\lib\ejs.js:235:18)
at tryHandleCache ({__dirname}\node_modules\ejs\lib\ejs.js:274:16)
at exports.renderFile [as engine] ({__dirname}\node_modules\ejs\lib\ejs.js:491:10)
at View.render ({__dirname}\node_modules\express\lib\view.js:135:8)
at tryRender ({__dirname}\node_modules\express\lib\application.js:657:10)
at Function.render ({__dirname}\node_modules\express\lib\application.js:609:3)
at ServerResponse.render ({__dirname}\node_modules\express\lib\response.js:1039:7)

-------------### [ERROR MESSAGE ENDS HERE]--------------

[References]

app.js
image

views/list.ejs
image

console
image

@RyanZim
Copy link
Collaborator

RyanZim commented May 26, 2023

EJS is unaware of any HTML syntax; EJS will still interpolate normally within comments. Obviously .. is not valid Javascript, hence the error.

@RyanZim RyanZim closed this as completed May 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants