electron-webpack
electron-webpack copied to clipboard
Working with threads.js, resolving node modules issue
- 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
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.