Reputation: 20526
On many of my EJS pages I have the following code:
<%- include('elements/fbviewpagepixel.ejs') %>
It works perfectly fine except on this one page. On that one pages it gives me an error saying include is not a function
. It looks like I was able to fix it by changing the code above to the following:
<%- include elements/fbviewpagepixel.ejs %>
Why does the first version work on all of my pages except this one? Why does it give me an error on this one page? What is even the difference between the two?
Upvotes: 9
Views: 7350
Reputation: 4216
Apart from the EJS bug mentioned in two of the other answers (an issue with parameter naming errors with a message about include function) there must be an issue with different EJS versions.
In my project setup I have the following packages:
"ejs": "^3.1.6",
"ejs-webpack-loader": "^2.2.2",
When I use ejs
with an express server to compile templates on the fly at each user request, the syntax must be:
<%- include('elements/fbviewpagepixel.ejs') %>
When I use ejs-webpack-loader
to pre-compile static files to be served by an Apache web server, the syntax must be:
<%- include elements/fbviewpagepixel.ejs %>
I haven't checked which EJS version is exactly used by the Webpack loader, but I reckon it must be different from v3.
Upvotes: 1
Reputation: 469
In the later versions of EJS the "client" parameter key is reserved, and will therefore cause this error. Rename the key and it'll resolve your issue.
Upvotes: 19
Reputation: 175
I think, this issus come from parameter passed in list. I had the same issus on rendering my user:
res.render("profil-client.ejs", {
client: myClient
});
But when I rename my parameter like this:
res.render("profil-client.ejs", {
r_client: myClient
});
No more error. I'm not sure, but I think ejs use attribute "client" for internal usage. So I just rename my parameters...
Upvotes: 5
Reputation: 166
I had this same issue; I worked around it by deleting my node_modules folder and running a fresh > npm install.
Wish I could tell you exactly why this fixed things, but I went from having this error to things running fine afterwards.
Upvotes: 1