I have Node.js v12.13.0 installed but still, I am getting below error. I have checked lots of questions regarding this but solution in all the question is updated node version.
Uncaught TypeError: crypto__WEBPACK_IMPORTED_MODULE_5__.generateKeyPairSync is not a function
at Login.render (Login.jsx:31)
at finishClassComponent (react-dom.development.js:17098)
at updateClassComponent (react-dom.development.js:17051)
at beginWork (react-dom.development.js:18513)
at HTMLUnknownElement.callCallback (react-dom.development.js:189)
at Object.invokeGuardedCallbackDev (react-dom.development.js:238)
at invokeGuardedCallback (react-dom.development.js:291)
at beginWork$1 (react-dom.development.js:23055)
at performUnitOfWork (react-dom.development.js:22022)
at workLoopSync (react-dom.development.js:21995)
at performSyncWorkOnRoot (react-dom.development.js:21613)
at scheduleUpdateOnFiber (react-dom.development.js:21045)
at updateContainer (react-dom.development.js:24194)
at react-dom.development.js:24577
at unbatchedUpdates (react-dom.development.js:21763)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:24576)
at Object.render (react-dom.development.js:24659)
at Module../src/index.js (index.js:27)
at __webpack_require__ (bootstrap:781)
at fn (bootstrap:149)
at Object.1 (PlayerStore.jsx:21)
at __webpack_require__ (bootstrap:781)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
Judging by the stacktrace, it looks like this code is running in the browser. The crypto.generateKeyPairSync
API is only available in Node.js. Basically, it can only be used server-side, not in the frontend.
You would need something like the Web Crypto API, built into modern browsers. Here is an example RSA key pair generation:
let keyPair = window.crypto.subtle.generateKey(
{
name: "RSA-OAEP",
modulusLength: 4096,
publicExponent: new Uint8Array([1, 0, 1]),
hash: "SHA-256"
},
true,
["encrypt", "decrypt"]
);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With