andywer/threads.js

Building React with webpack 4 and a node module that uses threads.js

Carl-Hughes-Cerberus opened this issue · 1 comments

I'm trying to build a react website which contains a custom built node module, and I want to make use of worker threads in this node module.

I've added the react plugin to the react webpack config: plugins: [new ThreadsPlugin()] with const ThreadsPlugin = require('threads-plugin'); at the top.

Ive followed the examples and I when it comes to create a worker I get

Refused to execute script from 'http://localhost:3000/static/js/add.js' because its MIME type ('text/html') is not executable.

I'm guessing this is because it's losing the add.js file location within the webpack as when you navigate http://localhost:3000/static/js/add.js it returns a 404 web error, but I don't know how to correct for this.

got a similar issue here. created a node package and added it to my main project.

when i try to use workers like this in development, it returns a 404 not found.
await spawn(new Worker('./yourworker.ts'))

when i run workers in develoment like this it works:

await spawn(new Worker(new URL('./yourworker.ts', import.meta.url)))

but as soon as i create a production build, it generates multiple files:

i get the intended index.js and additional files like somenumbers.index.js eg. (660.index.js).

i tried to copy everything on to the prod server, but as soon as the worker is called, a request is made to something like "https://yourproject/660.index.js", resulting in 404.

any ideas how to get a production build running? what am i missing?

help would be really appreciated.

thanks

edit:

im using webpack 5.73 & node v16.13.2

edit2:

consider my issue resolved.

await spawn(new Worker(new URL('./yourworker.ts', import.meta.url))) spawning a worker like this works fine, even on production. i probably somehow messed up and did not correctly copy all xxx.index.js files