question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Is it possible to get the line number in the ejs errors?

See original GitHub issue

I originally posted this question on StackOverflow. This is the original post:

(Suppose) I have a huge ejs file containing JavaScript snippets. When I compile it, I get the following error:

SyntaxError: Unexpected token ) in mytemplate.ejs while compiling ejs

While it’s obvious there is a syntax error in my template, I can’t know where the error is.

I have full access to the error object so, I was thinking if somewhere the error contains the line with the problem (in a similar way like the JavaScript engines tell you that there is a problem on a specific line).

I tried to access the err.stack field, but it only shows me the error origin (which comes from the ejs library), so that’s not really helpful.

Is there a way to know where the syntax error is in the ejs file?

I’m using the ejs package.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:36 (22 by maintainers)

github_iconTop GitHub Comments

1reaction
dgofmancommented, Feb 8, 2016

@ciroreed You solution shouldn’t work. @IonicaBizau I fixed issue in code related in template. But your in compilation error (Syntax Error) handling outside template try/catch block. When I will get a time I will deep look how to fix it. Currently I don’t have experiences writing invalid JavaScript code 😃

0reactions
Meignanamcommented, Jul 15, 2020

guys, could you help me , which kind of error , i am getting lag perticular issue

SyntaxError: Unexpected token ‘/’ in E:\PASSPORT\views\register.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 (E:\PASSPORT\node_modules\ejs\lib\ejs.js:661:12) at Object.compile (E:\PASSPORT\node_modules\ejs\lib\ejs.js:396:16) at handleCache (E:\PASSPORT\node_modules\ejs\lib\ejs.js:233:18) at tryHandleCache (E:\PASSPORT\node_modules\ejs\lib\ejs.js:272:16) at View.exports.renderFile [as engine] (E:\PASSPORT\node_modules\ejs\lib\ejs.js:489:10) at View.render (E:\PASSPORT\node_modules\express\lib\view.js:135:8) at tryRender (E:\PASSPORT\node_modules\express\lib\application.js:640:10) at Function.render (E:\PASSPORT\node_modules\express\lib\application.js:592:3) at ServerResponse.render (E:\PASSPORT\node_modules\express\lib\response.js:1012:7)

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is it possible to get the line number in the ejs errors?
I tried to access the err.stack field, but it only shows me the error origin (which comes from the ejs library), so that's...
Read more >
Error.prototype.lineNumber - JavaScript - MDN Web Docs
The lineNumber data property of an Error instance contains the line number in the file that raised this error.
Read more >
ejs-lint - npm
EJS-Lint replaces everything outside a scriptlet tag with whitespace (to retain line & column numbers) and then runs the resulting (hopefully) ...
Read more >
EJS -- Embedded JavaScript templates
It's easy to debug EJS errors: your errors are plain JavaScript exceptions, with template line-numbers included. Active development. EJS has a large community ......
Read more >
Top 10 Most Common Node.js Developer Mistakes - Toptal
pattern on all callback function arguments - the first argument of all callbacks is expected to be an error if one happens. Mistake...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found