iohook
iohook copied to clipboard
Cannot find ihook.node after build in electron-forge bases electron app
Expected Behaviour: iohook should work after the electron build using electron forge on Windows
Current Behaviour: When I run electron-fore start I am getting Cannot find the module 'C:\Users\Windows.User1\Desktop\Projects\desktop-screen-capture.webpack\main\builds\electron-v87-win32-x64\build\Release\iohook.node' Require stack:
- C:\Users\Windows.User1\Desktop\Projects\desktop-screen-capture.webpack\main\index.js
- C:\Users\Windows.User1\Desktop\Projects\desktop-screen-capture\node_modules\electron\dist\resources\default_app.asar\main.js This is my current setup: "iohook": { "targets": [ "node-83", "electron-87" ], "platforms": [ "win32", "darwin" ], "arches": [ "x64", "ia32" ] }, iohook is in my dependencies "dependencies": { "@sentry/electron": "^2.4.1", "axios": "^0.21.1", "check-disk-space": "^3.0.1", "copy-webpack-plugin": "^6.2.1", "electron-squirrel-startup": "^1.0.0", "iohook": "^0.9.3", "source-map": "^0.7.3", "winston": "^3.3.3", "winston-loggly-bulk": "^3.2.1" }
Your Environment electron : 12.0.4 node: 14.0 Operating System and version (desktop or mobile): Windows 10
If you added the "iohook": {"targets": [... to your package.json after installing iohook, you probably just need to reinstall iohook, that way its install script will detect the needed versions and download the prebuilds.
@marcelblum I have done this 2-3 times already. But still getting the same error in both local builds and prod build. I can see binaries in node_modules/iohook/builds folder.
one more things setting
externals: {
iohook: "iohook"
}
in the mainprocess webpack config make it work in dev mode. But in release mode when I build executable its shows the same error.
Sorry I don't have experience using the Webpack plugin in Forge but that may be the source of your issue, the Webpack docs on externals says:
The externals configuration option provides a way of excluding dependencies from the output bundles. Instead, the created bundle relies on that dependency to be present in the consumer's (any end-user application) environment
I do have an Electron 12 project that uses Electron Forge with iohook and I don't have any such problems. My Forge config has a line that ensures the iohook files get included in the packaged app, I am using asar but exclude the binaries from the asar to avoid issues:
packagerConfig: {
asar: {
unpack: "**/*.+(node|"+((process.platform == "darwin") ? "dylib" : "dll|exe")+")",
smartUnpack: true
},
...
I am not using asar packaging. The final dependency of the packaged app is empty (i.e node_modules) Can you try that and let me know . It's a boilerplate from forge https://www.electronforge.io/templates/webpack-template. It should not take you 10-15 min to test.
@deepanshushukla I'm not really sure what you're asking me to test at that template link. I'm not that familiar with Webpack (and honestly don't understand why it would be used in an Electron project but that's a different discussion...). I think your best bet, rather than trying to get Webpack to cooperate, is to add a specific Forge config directive such as postPackage to explicitly place a copy of the needed iohook files in the packaged app's node_modules.