mde/ejs

Why is the result of using await to obtain promise in ejs [object promise]?

xiaowang-create opened this issue · 3 comments

Our company's native development encountered this problem, help!

Without any example code, it's hard for me to figure out what issue you're encountering.

Try set async to false

const html = await ejs.renderFile(
    path.resolve("src/template", "index.ejs"),
    {},
    { async: false, cache: false },
);
mde commented

The async setting needs to be set to true, yes. Also worth noting that only the file I/O is async. It's generally more efficient if you can to do your I/O up front and keep template strings in a cache if you can.