Skip to content
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

Externalizing native dependencies doesn't seem to work with Electron #42

Open
rathboma opened this issue May 16, 2021 · 5 comments
Open

Comments

@rathboma
Copy link

Firstly, 👋 @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
@linonetwo
Copy link

linonetwo commented May 30, 2021

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.

@linonetwo
Copy link

linonetwo commented May 30, 2021

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.

@linonetwo
Copy link

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.

@rathboma
Copy link
Author

rathboma commented Jun 7, 2021

I had this work with a node worker, but it does not work for a we worker with node integration enabled unfortunately

@linonetwo
Copy link

My worker has node integration too, you can just external all node-related things, and import them as usual in the code.

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