For everyone like me who had the same error because you are making the app cross-compatible with bun, node, and deno, the right answer is to make sure that you are passing .pem files contents as an utf8 text.
I had to add "utf8" as the second argument to the readFileSync
function from the fs-extra