Includes now throwing errors
See original GitHub issueAfter updating to the latest version of EJS, I am now getting errors while compiling my EJS templates.
The error message is:
SyntaxError: Unexpected token .
I believe the lines causing these issues are include
lines such as the following, as when removing such lines the errors cease.
<% include ../partials/bootstrap/bootstrap_header.ejs %>
<% include ../partials/main_components/head_to_body.ejs %>
I couldn’t find any changes in the changelog which would cause this. Thanks,
Issue Analytics
- State:
- Created 4 years ago
- Comments:11 (2 by maintainers)
Top Results From Across the Web
throw - JavaScript - MDN Web Docs - Mozilla
The throw statement throws a user-defined exception. Execution of the current function will stop (the statements after throw won't be executed) ...
Read more >How to Throw Exceptions in Java - Rollbar
Throwing an exception is as simple as using the "throw" statement. You then specify the Exception object you wish to throw. Every Exception...
Read more >Types of exceptions that can be handled by tri-catch
Basically you catch pure JavaScript errors and ServiceNow APIs only throw real errors in rare cases. Unfortunately, you have to check the ...
Read more >How can I write a test which expects an 'Error' to be thrown in ...
js module I have the following code: throw new Error("Parsing is not possible");. Now I try to write a ...
Read more >Error handling, "try...catch" - The Modern JavaScript Tutorial
For all built-in errors, the error object has two main properties: ... Now catch became a single place for all error handling: both...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Ok, sorry for the lacking research.
For anyone else with the issue, you can change the old version of include:
<% include ../partials/bootstrap/bootstrap_header.ejs %>
to:<%- include('../partials/bootstrap/bootstrap_header.ejs') %>
It’s in the current changelog: “Removed legacy preprocessor include.” That usage of include is leftover from the very old v1, and was left for one major version (and for quite a long time) for backward compatibility.
We are following the semver convention of a major version bump when changing the public API. In fact, this hacky legacy feature was never actually documented in v2, but there were tests for it, so we have done a major version bump to v3. If your app depends on this feature, you can continue to install a v2.x.
Otherwise, you can convert to the modern
include
function call that is well documented, well supported, and will continue to exist in all future versions of EJS.