Electron package fails to load native module dynamically
Closed this issue · 5 comments
Version: 4.2.6
Short overview
A simple electron app that just moves mouse to co-ordinate (100,100) when started.
Issue occurs on
- Dev/Host system
node version: v23.9.0
OS type and version: MacOS
Detailed error description
Error: Could not dynamically require "/Users/xyz/work/my-app/electron-app/out/my-app-darwin-arm64/my-app.app/Contents/Resources/app.asar/build/libnut.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.
Full code sample to reproduce
main.ts looks like -
const { keyboard, Key, mouse, Point, straightTo, centerOf, screen } = require("@nut-tree-fork/nut-js");
mouse.move([new Point(100, 100)]);Additional content
The electron app works fine when started using npm run start, but once a package is created using npm run package and then the binary is directly run, the app fails with below error -
Error: Could not dynamically require "/Users/xyz/work/my-app/electron-app/out/my-app-darwin-arm64/my-app.app/Contents/Resources/app.asar/build/libnut.node". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.
Please provide any (mandatory) additional data to reproduce the error (Dockerfiles etc.)
The app uses electronforge to simplify the packaging
Hi @krusadellc 👋
this problem most likely stems from missing/wrong config when bundling the application.
Did you look into the suggestion outlined in the error message?
yes, I already tried dynamicRequireTargets, ignoreDynamicRequires, extraResources, etc. Nothing seemed to help :(
Can you link a repo?
And which OS are you using?
@krusadellc Any update?
Closing due to inactivity. Feel free to reopen on updates.