I just updated EJS from 2.7.4 to 3.1.5 and some other packages in my project. Upon doing it, I can't access any of the webpages but getting an error instead. Apparently all of the pages throws the same error. Besides that I get VS Code errors in some of the code in my ejs template which didn't matter before. I mean the errors were there before I updated all the npm packages and the app worked perfectly fine.
This is the endpoint:
router.get("/", async (req, res) => {
try{
const url = `http://api.example.co/?key=${process.env.API_KEY}`;
const fullData = await axios.get(url);
res.render("../views/index", {data: fullData});
}catch(err) {
res.render("../views/index", {data: null});
}
});
This is the error:

This is how I get data in my ejs template:
<% if(data){ %>
Name <%= data.name %>
<% } %>
This is the code in my script tags in my ejs template which shows red underline:

<script type="text/javascript" >
<% if(data) { %>
var map = L.map('map').setView([<%= data.latitude %>, <%= data.longitude %>], 11);
var marker = L.marker([<%= data.latitude %>, <%= data.longitude %>]).addTo(map);
L.tileLayer('https://api.maptiler.com/maps/streets/{z}/{x}/{y}.png?key=boomBoomBoomm', {
attribution: '<a href="https://www.maptiler.com/copyright/" target="_blank">© MapTiler</a> <a href="https://www.openstreetmap.org/copyright" target="_blank">© OpenStreetMap contributors</a>'
}).addTo(map);
<% } %>
</script>
What could be the issue? Am I doing something wrong? Is the update of something clashing with something else? Please help!
Found the problem. Apparently the newer versions of EJS requires including partials of header and footer in a different way than before.
So changing this:
<% include ./partials/header %>
to
<%- include ("./partials/footer") %>
fixed the issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With