-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Webpack5 #43
Comments
Currently workaround #37 (comment) // @ts-expect-error it don't want .ts
// eslint-disable-next-line import/no-webpack-loader-syntax
import workerURL from 'threads-plugin/dist/loader?name=worker!./gitWorker.ts'; is working, so this is not a hurry. |
Well, seems there are lots of changes compare to google's version https://github.com/andywer/threads-plugin/compare/master...GoogleChromeLabs:master?expand=1 It can gives some insight about how to upgrade, but it makes me wonder, can I just use |
re: #43 (comment) How are you able to use the workaround? From what I can tell, you still must have threads-plugin installed? It looks like this workaround won't work for me, but want to confirm... |
Hi @hidesminimally it works on my side https://github.com/tiddly-gittly/TiddlyGit-Desktop/blob/445c9a36c7e98bc7498fcba72b1ca84edcb861eb/src/services/git/index.ts#L17-L31 , maybe you can also checkout my webpack config. |
Doing this leaves webpack to copy across the files to dist, though i can't seem to get it working with typescript const workerUrl = new URL('./my-worker.ts', import.meta.url);
const relativePath = path.relative(__dirname, workerUrl.pathname);
spawn(new Worker(relativePath)), |
My config works with electron forge, but didn't test with normal nodejs |
@DustinJSilk I think you have a contradiction in your code snippet: Maybe it can work in browsers after all, if webpack resolves the Btw, what's the error? |
Oh, I didnt realise that would be the case. The reason it doesn't work with typescript is because webpack only copies the entry TS file to the dist folder which means all imports are broken. I setup a separate webpack config in the meantime that compiles any Not ideal as its a bit messy but its a start! EDIT |
@andywer Following on from this thread and example repository, it seems to work well for webworker, but it doesn't seem to work for node worker threads in TS. |
Right I've managed to get it to compile with a little hack. Webpack 5 seems to only compile DOM URLs, not Node URLs. So I've added "DOM" to my tsconfig import { Worker } from "worker_threads";
import { URL as NodeURL } from "url";
const worker = new Worker(
new URL("./workers/foo.worker.ts", import.meta.url) as NodeURL
); Example repo here: https://github.com/DustinJSilk/web-worker-ts-webpack-test |
That's super interesting! Thanks for sharing, @DustinJSilk 👍 Gotta try that myself… |
@DustinJSilk you just rescued me from a 3 day odysee of getting workers to run with webpack 5. Thanks so much! |
This works in create-reacte-app v5 in the browser too:
While it will still have this error on the cli console:
But I tried to add a log to the worker, apparently the worker is bundled and loaded. It is possible to ignore this warning in webpack by using configure: (webpackConfig) => {
const ignoreWarnings = [{ module: /inversify/, message: /Failed to parse source map/ }, { message: /No instantiations of threads/ }];
return { ...webpackConfig, ignoreWarnings };
}, |
I have a similar issue with webpack 5, apparently the fallback
doesn't work so I used
to manually replace, and it works for me |
Can be changed to this, because
'imported var'
is not supported.But still get
TypeError: ParserHelpers.addParsedVariableToModule is not a function
, and I searched issue GoogleChromeLabs#88 seems have a workaround, butParserHelpers.getModulePath
is gone too:this update is useless
to
The text was updated successfully, but these errors were encountered: