#Bundle web worker for npm package

1 messages · Page 1 of 1 (latest)

honest oar
#

Hi, i'm trying to bundle web worker to make an react npm package. The problem comes when i try to import package to another project... The browser can't find the worker

#
const worker = new Worker(new URL('./workers/arnft.worker.ts', import.meta.url), { type: 'module' });
#

the import code

#
Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "text/html". Strict MIME type checking is enforced for module scripts per HTML spec.
#

the error

#

Idk, i try to install this @surma/rollup-plugin-off-main-thread but the results are the same

honest oar
#

the problem may be that worker get's under assets/arnft.worker.505770f1.js

#

and react just not serving it from package...

#

mkay if i copy arnft.worker.4e733d5c.js to public it does work

honest oar
#

But anyone has any clue how can i encode it to base64 directly?

pearl snow
#

it looks like it is serving the script but it's not what it expects it to be