wilix-team / iohook

Node.js global keyboard and mouse listener.
https://wilix-team.github.io/iohook
MIT License
1.2k stars 291 forks source link

Module could not be found when app is packaged in asar #396

Closed jove0610 closed 2 years ago

jove0610 commented 2 years ago

The error appears when I packaged the app as asar. There is no error during the packaging and it will package successfully, only when I open the application I got the error. The error will not appear and the app will open normally if I did not package it as asar.

Expected Behavior

App will work when I packaged an app as asar.

Current Behavior

Here is the error: error

I can only get the image of the error. I can't copy-paste the text.

Possible Solution

Steps to Reproduce (for bugs)

  1. Install electron-forge boilerplate npx create-electron-app@latest my-app
  2. Downgrade to electron@17
  3. Install iohook, write console.logs in index.js to test iohook.
  4. Enable asar during packaging in package.json:
    "config": {
    "forge": {
      "packagerConfig": {
        "asar": true
      },
      // maker config
    }
    },

Context

I am trying to package my app in asar file, I read in electron docs that it optimizes the app. Also, it'll look more professional if the app is in asar.

Your Environment

Thanks

marcelblum commented 2 years ago

Best to exclude the iohook binaries (and any other native module binaries you might be using) from the asar. Adding this option to packagerConfig covers most cases:

packagerConfig: {
    asar: {
        unpack: "**/*.+(node|dll|exe)",
        smartUnpack: true
    }
}
jove0610 commented 2 years ago

Thanks @marcelblum