Open brikis98 opened 6 years ago
Update: when I use the TypeScript bindings for EJS, I even get an error that fileLoader
is readonly and cannot be overwritten! If I use import ejs = require("ejs")
, that error goes away, but include
still works...
It turns out the cause of this is that in ES6 and TypeScript, all imports are considered constant. So, to work with ES6/TypeScript, EJS will need to expose a new way to override the file loader.
Workaround: override the include
keyword:
const fileLoader = (filePath: string): string => {
throw new Error(`File loading not supported. Tried to load: ${filePath}.`);
};
const compiledTemplate = ejs.compile(`Hello, <%- include("foo") %>`);
// Will throw "File loading not supported" error
compiledTemplate({include: fileLoader});
I'm trying to use EJS with TypeScript as follows:
I ran the code above, and it succeeded, with the
include
offoo
working just fine. This indicates that overridingejs.fileLoader
had no effect. I triedimport ejs = require("ejs")
, but that also didn't help.Any suggestions on what I might be doing wrong?