Open yovanoc opened 3 years ago
Hey @yovanoc. What does not work / what error do you see? 😉
I got this warning:
WARNING in No instantiations of threads.js workers found.
Please check that:
1. You have configured Babel / TypeScript to not transpile ES modules
2. You import `Worker` from `threads` where you use it
And when call a method, the main thread timeout in 10 sec.
I think it is related to single js final build, or idk, babel-preset-typescript maybe, because i can't change like ts-loader the compiler options
Really hard to tell from here. Can you share the code where you import spawn
and where you instantiate a new Worker()
?
I think the code is correct, its configuration things
Yep, code looks alright. I think the Babel config is the trouble maker here:
"@babel/preset-env",
{
(…)
"modules": false,
Babel will transpile the modules away and the threads-plugin can then no longer identify the import statement that doesn't exist anymore.
Any reason not to do "modules": true
? Webpack should be able to resolve everything just fine.
From the readme
Ahh, sorry. Nevermind. I confused the semantics of the setting…
Yeah I'm so confused too... I've done settings all day and no way to get this working :/
I am getting this too when I try to update all my dependencies for my project. https://github.com/FoxelFox/voxel-octree
WARNING in No instantiations of threads.js workers found.
Please check that:
1. You have configured Babel / TypeScript to not transpile ES modules
2. You import `Worker` from `threads` where you use it
For more details see: https://github.com/andywer/threads-plugin
ERROR in ./src/index.ts 12:0-45
Module not found: Error: Package path ./dist is not exported from package /Users/fox/coding/voxel-octree/node_modules/threads (see exports field in /Users/fox/coding/voxel-octree/node_modules/threads/package.json)
webpack 5.15.0 compiled with 1 error and 1 warning in 2885 ms
Same problem. Warning always there after upgrading. Using Webpack 5.
@FoxelFox @eranimo This happens only after upgrading to webpack 5 and you are using threads-plugin v1.4.0?
If so, can you try going back to webpack 4 for a moment, but use the latest threads-plugin v1.4.0 and check if that works? All that would be super helpful information 👍
Yes this happens only with webpack 5 and i am using threads-plugin v1.4.0. I will stick with 4 for a moment.
I have spent several days looking for solution with webpack 5(babel+typescript+react) and finally found workaround:
import "threads/register"
plugins: [ new ThreadsPlugin({globalObject: 'self'}),]
import {spawn, Thread, Worker} from "threads"
// @ts-ignore
import pdfExportUrl from "threads-plugin/dist/loader?name=pdfExport!./worker/pdfExport.ts"
... const pdfExport = await spawn(new Worker(pdfExportUrl)); const pdfContent = await pdfExport (data); await Thread.terminate(pdfExport );
You don't need the threads-plugin at all with webpack 5 (see #37). Will update the docs accordingly!
Nevertheless, thanks for sharing your findings here 👍
Also having problems with this on webpack 5.10.
Using the following babel presets:
return {
presets: ['@babel/preset-typescript', ['@babel/preset-env', {
// https://github.com/andywer/threads-plugin
modules: false
}], '@babel/preset-react'],
plugins: runPlugins,
};
Tried with and without using the plugin, also tried the import.meta.url
method.
Actually I have these configs and it does not work, so can you tell me what I'm doing wrong (of course I have
"module": "ESNext",
in my tsconfig) big thanks