mde / ejs

Embedded JavaScript templates -- http://ejs.co
Apache License 2.0
7.7k stars 841 forks source link

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

Closed xiaowang-create closed 1 year ago

xiaowang-create commented 1 year ago

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

RyanZim commented 1 year ago

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

ben1one commented 1 year ago

Try set async to false

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

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.