threads-plugin
threads-plugin copied to clipboard
Externalizing native dependencies doesn't seem to work with Electron
Firstly, :wave: @andywer! Thank you so much for making Threads and threads-plugin. It's great.
I maintain https://github.com/beekeeper-studio/beekeeper-studio which is an electron app and I'm trying to add a web worker that uses better-sqlite3
.
I've enabled native module support in Electron, so it should work, but I'm getting this error, which seems to indicate that the better-sqlite3 module is not in the webpack externals list.
I'm providing it as an external to both the plugin, and to the main webpack config, so not sure if I'm doing something wrong (I probably am).
Here's a self contained project where I replicate the issue (see the console for the error): https://github.com/rathboma/bettersqlite3-electron-vue
Run with:
yarn install
yarn electron:start
I can confirm that external config is not working:
externals: {
'@tiddlygit/tiddlywiki': '@tiddlygit/tiddlywiki',
},
externalsType: 'commonjs',
externalsPresets: { electronMain: true },
Seems this plugin is not reading the external config.
Webpack external plugin only works in webpack4 https://github.com/tiddly-gittly/TiddlyGit-Desktop/blob/8759bdf433b9e87972d3e12c991743a4185a3b8d/webpack.plugins.js#L34-L41
For webpack5, there is no way to external things from worker.
I've created https://github.com/linonetwo/webpack5-externals-plugin
You can do
new ExternalsPlugin({
type: 'commonjs',
include: path.join(__dirname, 'node_modules', '@tiddlygit', 'tiddlywiki'),
}),
new ThreadsPlugin({
target: 'electron-node-worker',
plugins: ['ExternalsPlugin'],
}),
To external things.
This issue canbe closed now.
I had this work with a node worker, but it does not work for a we worker with node integration enabled unfortunately
My worker has node integration too, you can just external all node-related things, and import them as usual in the code.