Reputation: 7191
PROBLEM
by some online examples you may use syntax like this
<%- include hello-world %>
or even you can use
<%- include('hello-world'); %>
you may get error that include missing filename
Exception occurred: Error: `include` requires the 'filename' option.
Q where is the problem if my syntax is right?
Upvotes: 3
Views: 3778
Reputation: 3853
It's 03/2023 and EJS latest version is v3.1.8.
Info you are using EJS@v2 such as v2.5.4 you may want to read this:
EJS has a bug on relative paths detection that impacts windows but not unix systems that results in above error message as you can see here
Upgrading to version 2.7.4 will fix the issue.
If you are using version3 this shouldn't be an issue.
Upvotes: 0
Reputation: 7191
Answer is in backend "file path"
but even if you used the proper path you get an error too
var fs = require('fs');
ejs.render(fs.readFileSync(__dirname + '/templates/include.ejs', 'utf8'), {});
right answer is "use renderFile"
ejs.renderFile(__dirname + '/templates/include.ejs', {}, function(err, result) {
if (!err) {
res.end(result);
}
else {
res.end(err.toString());
console.log(err);
}
});
ref
Upvotes: 5