-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[Case Study] Electron #1020
Comments
Hey! I think @merceyz has made some experiments, maybe they'll have more insight to share! If I remember correctly, the main issue is that part of Electron is running within a browser context where the libzip layer cannot be instantiated synchronously on the main thread due to arbitrary Chrome restrictions - preventing to load the other files 🙁 There's also something about |
You seem to be correct regarding libzip being the culprit, at least for this crash. It's confusing that v9 of Electron (on Chrome 82) doesn't seem to have this problem (Chrome 80 does). Most (many?) Electron apps will have Webpack build the application before passing it to Electron to run, perhaps running Electron explicitly not with Any tools that copy the process.env and spawn the electron process with it will need to delete the Our internal toolchain handles that spawn and we can delete the require call, however users that boot Electron via Would it be possible to add a flag / environment variable to Regarding bundling, there might need to be a custom webpack plugin that takes the externals entries in Webpack and 'unplugs' those specific dependencies into the node_modules folder, a partial My high level goal here is essentially for support of native modules in Electron with PnP using a bundler. I'll have to look into how electron-builder packages up the app. Unfortunately it seems like it makes a lot of those node_modules assumptions. But it also looks like they've added some explicit support? They have an issue here already. electron-userland/electron-builder#4688 Having PnP work as a runtime in Electron isn't an explicit goal for me. Does Yarn PnP's require override explicitly remove the checks for files in node_modules? If a node_modules folder exists, and contains a package, and you're running PnP and you require that package, will there be any conflict? I assume there's some conflict given this functionality to explicitly remove any node_modules folders that exist after a PnP installation.
Several hours of work later I've done some prototyping. I prototyped a couple custom linker solutions. One that unplugged specific packages into the node_modules folder, but then you end up needing their dependencies unplugged and that becomes a slippery slope that I don't want to go down. Another variation copied the packages with native modules into node_modules but kept the JS around in PnP. This exposed the issue that the standard seems to be to use the bindings npm package to grab the file location of the .node native file. https://github.com/tessel/node-usb/blob/249f0a96afd5dc91cb0c096f195c5e957607e5ce/usb.js#L1 It uses the v8 stack trace API to figure out what file called the function, to then start searching for the bindings file. For some reason in my testbed, the At this point I'm leaning toward a Webpack plugin that at a high level does this:
I prototyped a Webpack plugin that would find these bindings calls and rewrite them, injecting the caller statically in the form This gets us to the stage of this:
We can replace 'that' module with one that looks like:
And we don't need rewrite the consumers of bindings at all. I reckon a custom Yarn resolver and fetcher could be used to apply the prebuild-install spec. Yarn PnP knows exactly what electron version is installed! It could fetch the prebuild files and prevent the need for these packages to be unplugged in the first place. Webpack can then treat the .node files like any other asset, hash them and store them where-ever. A couple days later I've had some more time. I wrote a yarn plugin that detects dependencies on https://github.com/electricui/yarn-prebuilds This can then be used with a Webpack plugin or Rollup plugin to treat the With this I'm successfully able to have Webpack run in PnP land, bundle everything (including the native files), then I run Electron, explicitly removing the |
Thank you for putting effort into this, @Mike-Dax! I went the Quick question, have you considering leaving the fetching to the packages containing the native modules, running Edit: Okay, |
@arcanis @alecmev @Mike-Dax is the issue electron/forge#3611 related to yarn's PnP (this issue) or electron/electron-forge? |
First off, thank you so much for your hard work on this project. I'm very excited to have Yarn PnP integration in our projects.
What package is covered by this investigations?
Electron
Describe the goal of the investigation
Clear Electron integration, a lack of v8 crashes.
Investigation report
The current latest stable version of Electron has a v8 crash when booting with Yarn PnP enabled.
With
nodeLinker: node-modules
enabled, no such crash occurs.When upgrading to electron v9 beta branch, no such crash occurs.
I've opened an issue at Electron's end electron/electron#22472
I have a minimum reproducible example here: https://github.com/Mike-Dax/electron-yarn-pnp-crash.
The tentative release date for v9 will be 2020-04-28
The text was updated successfully, but these errors were encountered: