-
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
electron - bundling with asar gives 'Cannot find module 0.bundle.worker.js' error #17
Comments
Hey @dinataranis, thanks for reporting. How do you think would the solution look like? The I could imagine that setting the |
Hi, @andywer, sorry for delay. |
I am not yet 100% sure how the solution eventually needs to look like, but I think we need some way to optionally pass a custom worker-path-rewrite function to the |
Hi @andywer,
(That's in typescript to make it more clear.) Just for checking, we have changed the code under
And it does find the module, but unfortunately, we get another error:
It makes sense since in
I'm not sure if it's related to threads or threads-plugin though. Any ideas? |
@raz-sinay No, the option should not go into the Might find some time to look into that tonight. |
@raz-sinay @dinataranis Can you try to apply this little patch to your Don't forget to update the diff --git a/src/index.js b/src/index.js
index f944e7c..e5515e8 100644
--- a/src/index.js
+++ b/src/index.js
@@ -31,6 +31,7 @@ export default class WorkerPlugin {
apply (compiler) {
let workerId = 0;
+ const rewritePath = this.options.rewritePath || (workerPath => workerPath);
compiler.hooks.normalModuleFactory.tap(NAME, factory => {
for (const type of JS_TYPES) {
@@ -74,7 +75,8 @@ export default class WorkerPlugin {
}
const loaderOptions = { name: opts.name || workerId + '' };
- const req = `require(${JSON.stringify(workerLoader + '?' + JSON.stringify(loaderOptions) + '!' + dep.string)})`;
+ const workerPath = rewritePath(dep.string);
+ const req = `require(${JSON.stringify(workerLoader + '?' + JSON.stringify(loaderOptions) + '!' + workerPath)})`;
const id = `__webpack__worker__${workerId++}`;
ParserHelpers.toConstantDependency(parser, id)(expr.arguments[0]); |
Hi, @andywer
|
@dinataranis @raz-sinay Ohh, sh**, you guys are right, of course. Sorry for the confusion… @dinataranis Can you try monkey-patching @raz-sinay The |
Hi, @andywer
So I added
It means, that all node modules which I use in workers files I have to include to |
@dinataranis Can you try |
Ping 👉 @dinataranis. |
Hi, @andywer
|
The small update.
It is because of the backslashes in the string. If we try to escape them first and only after what make the search, it should work.
|
Yeah, you can monkey-patch it for now using |
Try this commit 😉 |
I published the latest feature branch commit using a
|
Hi, @andywer
I didn't get your fresh changes, but I just added them manually (changed the |
@dinataranis Ohhh. That was me being stupid while publishing. Can you give |
Just a tiny thing, you have forgotten to change |
@andywer Was that merged to some version we can use? |
Ohh man. I was so busy, I completely forgot. It's merged and published as threads.js v1.4.0 now! 🙌 |
I think something is wrong with the regex. because I'm still getting: |
@raz-sinay To be on the safe side, can you list the following information?
|
Sure,
When I test the path against the regex |
Not sure if it's the regex. I just quickly tried it in a REPL and it matched:
Did you set the |
I did, also made sure that it was unpacked. |
@andywer We did some more investigation.
|
@andywer any news with this one? |
@raz-sinay Ohh, sorry.
Don't have a Windows system to test, besides in CI. I guess we should not |
Sounds good. |
I opened a follow-up PR andywer/threads.js#236 and published it under a @raz-sinay Give it a try – hope that does the job 😉 |
Works! |
This should probably be reverted (or optional) now that electron natively supports asar's electron/electron@06a00b7 |
Hi!
I am building an electron application with electron-webpack and electron-builder.
I am trying to use threadsjs.
When testing in dev mode everything works great, but unfortunately when trying to pack the app (using electron-builder), with the asar option, I am getting the following error:
`Cannot find module 0.bundle.worker.js``
I think it is caused by a mismatch in the worker's path.
Since packing with asar option causes the entire app to be bundled as a single file, it can't access the worker at runtime.
After searching the web for a bit I found the asarUnpack option (which specifies which files to unpack when creating the asar archive) is probably what we are looking for, but I think it requires changes in threads-plugin to allow worker files to be bundle as asarUnpack.
Code example with asarUnpack flag:
I have reproduced the issue with the basic template, it can be accessed from here.
When bundling with asar: false everything works as expected, but without we get the error above.
Bundling with asar: false is strongly not recommended solution, and it really affects the app performance.
We will be thankful if this can be solved.
P.S. I took the dependencies from my current project, but I get the same error, when I use the latest
Best regards.
The text was updated successfully, but these errors were encountered: