ejs icon indicating copy to clipboard operation
ejs copied to clipboard

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

Open xiaowang-create opened this issue 2 years ago • 1 comments

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

xiaowang-create avatar Oct 13 '22 16:10 xiaowang-create

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

RyanZim avatar Oct 13 '22 16:10 RyanZim

Try set async to false

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

ben1one avatar Dec 13 '22 02:12 ben1one

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.

mde avatar Dec 14 '22 18:12 mde