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

Can not find module "uiohook-napi" after installation .exe #43

Closed
batoolfatima2135 opened this issue Mar 27, 2024 · 9 comments
Closed

Comments

@batoolfatima2135
Copy link

batoolfatima2135 commented Mar 27, 2024

I am using electron forge with webpack and typescript, uiohook-napi is working properly in my development platform. Compiling the program is also working. But when I tried to install the .exe file this error is appearing.

Capture

My enviroment

uiohook-napi Version: ^1.5.3
Environment name and version: nodejs 20.9.0, electron: 29.1.5, electron-forge: ^7.3.1
Operating System and version: win32 x64

@marcelblum
Copy link

I think you need to force electron-forge to exclude uiohook-napi from the ASAR archive for it to work in packaged form. I am doing this using packagerConfig in my forge configuration, see https://www.electronforge.io/config/configuration#electron-packager-config. You can explicitly specify uiohook-napi to not be packed in the ASAR using the asar unpack or unpackDir options.

@batoolfatima2135
Copy link
Author

batoolfatima2135 commented Mar 27, 2024

Hey @marcelblum, I appreciate your help. Unfortunately, I tried what you suggested, but I'm still encountering the same error 😔.

Sharing my forge.config file code for your reference. Could you please review it and let me know if I've made any mistakes? I'm relatively new to Electron, so I apologize in advance for any beginner errors.

Thanks again!

packagerConfig: {
    asar: {
      unpack: "node_modules/uiohook-napi/**", // Exclude uiohook-napi from ASAR
    },
  },

@marcelblum
Copy link

You can test it by looking in the folder structure of your packaged app to see if the files are outside the ASAR as desired. If successful you should find the excluded files under \resources\app.asar.unpacked\. But actually if you want to exclude a whole folder you can use unpackDir instead of unpack. unpackDir: "node_modules/uiohook-napi" should do it.

@batoolfatima2135
Copy link
Author

batoolfatima2135 commented Mar 28, 2024

I have tried both unpackDir: "node_modules/uiohook-napi" and unpack: "node_modules/uiohook-napi/**" together as well as separately, but nothing works, stil the same error.
what i've tried so far:

 asar: {
      unpack: "node_modules/uiohook-napi/**", // Exclude uiohook-napi from ASAR
    },
asar: {
      unpackDir: "node_modules/uiohook-napi"
    },
asar: {
      unpack: "node_modules/uiohook-napi/**", 
      unpackDir: "node_modules/uiohook-napi"
    },

I am using electron-forge make command for creating packaged app and I cannot find \resources\app.asar.unpacked\, I can only see \resources\app.asar

@marcelblum
Copy link

if you're not seeing a \resources\app.asar.unpacked folder then something's not right in the way you have your packagerConfig set up. Either the config is not being properly passed to forge or there's some syntax error or something. As a quick test you can just try asar: false which should result in no asar being created, instead there should just be a \resources\app\ folder containing your source files (side note: this is also a good test to confirm that the asar was the problem preventing uiohook-napi from working in the first place). If you still have a \resources\app.asar file even with asar: false then your packagerConfig is being ignored or overridden.

@alexpargon
Copy link

alexpargon commented May 31, 2024

Hello all!

I'm having the same issue here: https://github.com/Dygmalab/Bazecor/tree/removeFocusAPI (open software with GPLv3 license so that you can compile it yourselves with yarn make)

I found this plugin from Forge to make use of the asar packager, but it fails either way.
https://www.electronforge.io/config/plugins/auto-unpack-natives

This only fails in Windows platforms, in Mac it's working perfectly when packed.

image

@alexpargon
Copy link

@batoolfatima2135 did you manage to solve the issue on your side?

@alexpargon
Copy link

alexpargon commented Jun 4, 2024

so, just for the record, I found the reason.

After updating xstate to v5, electron-forge started failing in the packaging process, to solve it, I had to update Typescript package from v4 to v5, but that broke the Windows native package's prebuilt binaries compilation.

The issue was within the filter in forge.config.ts at the packageAfterPrune function, and was due to a change in how the RegEx detected the prebuilds path to remove the precompiled binaries from other platforms than the one being compiled, it deleted them all, thus failing to execute when packaged.

Changing the filter to look for the platform independently solved this issue and maintained the optimization.

@batoolfatima2135
Copy link
Author

that's great you found solution @alexpargon, actually on my side I just used vite instead of webpack and it started working

@SnosMe SnosMe closed this as not planned Won't fix, can't repro, duplicate, stale Sep 8, 2024
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

4 participants