Error timingSafeEqual is not a function (crypto package)

When using the package crypto, specifically the function “timingSafeEqual” in my cloud function, I get this error: {“message”:“‘timingSafeEqual’ is not a function”,“name”:“TypeError”}

exports = async function() {
  var crypto = require('crypto');
  // ...
  return crypto.timingSafeEqual(Buffer.from(stored, 'hex'), buffer);
}

This only happens in atlas function environment, it runs well in local nodejs, not idea why I am getting the issue if the rest of the crypto package works well. And it is part of the module Crypto | Node.js v20.2.0 Documentation

Thank you if you have any idea.

1 Like