I'm trying to use "worker_threads" in my react-app for some cpu-intensive works. but react-app can't find "worker_threads" in node.js library.
Here is my code:
const {Worker} = require('worker_threads');
const path = require('path');
function fibonacci_worker(n) {
return new Promise((resolve,reject) => {
const w1 = new Worker(path.join(__dirname,'/fib.js'), { workerData: n });
w1.on('message',e => resolve(e));
w1.on('error',e => reject(e));
});
}
"npm start" script throws following error: "Can't resolve 'worker_threads' in 'C:\path\to\fibonacci.js'"
- node version: 12.13.0
- react-scripts version: 3.2.0