electron-userland / electron-userland/electron-webpack

Working with threads.js, resolving node modules issue

Open
#343 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
902
Forks
168
PR merge metrics
No merged PRs in 30d

Description

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

I'm trying to use [threads.js](https://github.com/andywer/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](https://github.com/andywer/threads.js#getting-started) 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](https://github.com/andywer/threads.js/issues/44) but it should work in Electron's main process as far as I understand.

Also, I've opened [an issue](https://github.com/andywer/threads.js/issues/203) in threads.js, but was told that the code looks fine and that it is probably an electron issue.

Am I missing something?

Thanks

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.