How can i require an npm module that you would normally do with cosnt package = require('package-name')
but inside a web worker?
I've been struggling with this and every time i get the following error: ReferenceError: __webpack_require__ is not defined
Any help would be appreciated :)
Update: Here is the worker:
async function handleMessage(dates){
const package = require('package-name')
//.....
}
export default handleMessage;
App.js:
const [calculateStatus, setCalculateStatus] = React.useState(false);
const [calculateWorker,
{ status: calculateWorkerStatus, kill: killWorker }
] = useWorker(handleMessage, {
timeout: 5000
});
const Test = () => {
calculateWorker(dates).then(result => {
console.log("Worker result", result);
});
};
I used create-react-app so webpack config is a bit tricky. I tried using React-app-rewired and tried the following override, but no luck:
module.exports = function override(config, env) {
config.node = { global: false, mode:"production"}
return config
}