node-webcrypto-ossl icon indicating copy to clipboard operation
node-webcrypto-ossl copied to clipboard

TypeError: (intermediate value).Crypto is not a constructor

Open dtruffaut opened this issue 5 years ago • 5 comments

const main = async () => {
  const crypto = new (await import('node-webcrypto-ossl')).Crypto();
}
main();

TypeError: (intermediate value).Crypto is not a constructor

NB : I cannot use require() since the library using this is a shared library between front and back, and I make a test on window to determine if I use window.crypto (front) or if I dynamically import node-webcrypto-ossl (server). Plus, ES2020 modules do not support require().

dtruffaut avatar May 10 '20 13:05 dtruffaut

Might be related in source code to https://stackoverflow.com/questions/42036349/uncaught-typeerror-intermediate-value-is-not-a-function ?

dtruffaut avatar May 10 '20 13:05 dtruffaut

It's not clear why you've got that exception. I've tried it locally and I don't have such error. image If you are using nodejs version upper then 10 you can use @peculiar/webcrypto module. It based on nodejs crypto API and doesn't require C++ addon.

I'm using [email protected]

microshine avatar May 10 '20 14:05 microshine

"node-webcrypto-ossl": "^2.1.0" node v14.0.0 Windows 10 64 bits

ossl

dtruffaut avatar May 10 '20 15:05 dtruffaut

Same error with "@peculiar/webcrypto": "^1.1.1"

dtruffaut avatar May 10 '20 15:05 dtruffaut

image

microshine avatar May 10 '20 20:05 microshine