Skip to content

Working with threads.js, resolving node modules issue #343

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

Open
yonigel opened this issue Jan 29, 2020 · 1 comment
Open

Working with threads.js, resolving node modules issue #343

yonigel opened this issue Jan 29, 2020 · 1 comment

Comments

@yonigel
Copy link

yonigel commented Jan 29, 2020

  • electron-webpack version: 2.7.4
  • electron-builder version: 21.2.0

I'm trying to use threads.js to work with web workers.

When I'm trying to use node modules in the main process's worker (i.e. path, fs), I'm getting following error:

Module not found: Error: Can't resolve 'fs' in '...\src\main'

But, when using this example it works (excluding the sha library).

For main window I'm using:

mainWindow = new BrowserWindow({
width: 900,
height: 680,
webPreferences: {
nodeIntegration: true,
nodeIntegrationInWorker: true
},
fullscreen: true
});

And instead of the example above I wrote this:

import { expose } from 'threads/worker';
import keyBy from 'lodash.keyby';
import fs from 'fs';
expose({
testWorker() {
const test = fs.readFileSync('/path');
return keyBy([]);
}
});

When using only keyBy it works fine, but when adding modules like path or fs I'm getting the error I've mentioned above.

I saw this closed issue but it should work in Electron's main process as far as I understand.

Also, I've opened an issue in threads.js, but was told that the code looks fine and that it is probably an electron issue.

Am I missing something?

Thanks

@alexweber
Copy link

This may or may not help but electron-webpack actually uses 2 different webpack configs/instances; one for main and another for renderer so you can't do stuff like remote requiring main stuff in the renderer and vice-versa like you would if it was a single webpack for both - which may be used in other boilerplates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants