I faced this issue in my dev environment when I tried to generate a key pair asynchronously, the stack is Laravel + React (Vite).
I was able to solve this by doing the following:
// declare a variable to point to a public resource of the minified version of prime worker
const worker = `${window.location.origin}/workers/prime/prime.worker.min.js`;
pki.rsa.generateKeyPair(
{
bits: 2048,
workers: 2,
workerScript: worker,
},
...
// package.json
// Automate the cp process; ensure to install copyfiles and also add to build.
"scripts": {
"copy-worker": "copyfiles -u 1 node_modules/node-forge/dist/prime.worker.min.js public/workers/prime/",
"dev": "npm run copy-worker && vite",
...
I faced this issue in my dev environment when I tried to generate a key pair asynchronously, the stack is Laravel + React (Vite). I was able to solve this by doing the following: