SnosMe / uiohook-napi

MIT License
162 stars 37 forks source link

App threw an error during load When I use electron-forge create a templates=webpack electron project #28

Closed focus-sc closed 1 year ago

focus-sc commented 1 year ago

It's right run when I use electron-forge create a normal electron project. But if I use templates=webpack or templates=webpack-typescript to create an electron project, it's will be abnormal when I use yarn start to run the project. This screenshot show the error: Error: No native build was found for platform=darwin arch=x64 runtime=electron abi=110 uv=1 libc=glibc node=16.17.1 electron=22.0.0 webpack=true; image

SnosMe commented 1 year ago

Look for potential solution in https://github.com/prebuild/node-gyp-build/issues/22

I'm using esbuild and have no issues https://github.com/SnosMe/awakened-poe-trade/blob/d1e30bfe754f2fbdc44e3ea12a6278e4d61cb242/main/build/script.cjs#L27

marcelblum commented 1 year ago

I ran into similar issues especially when trying to build a universal mac app, I had to disable auto rebuild via rebuildConfig: {onlyModules: []} in the forge config, and rename the uiohook-napi binary very platform-specifically to darwin-arm64/darwin.arm64.electron.110.napi.node. I think it's a problem with prebuildify trying to be a little too smart while infering filenames/versions. Hope this helps.

focus-sc commented 1 year ago

Look for potential solution in prebuild/node-gyp-build#22

I'm using esbuild and have no issues https://github.com/SnosMe/awakened-poe-trade/blob/d1e30bfe754f2fbdc44e3ea12a6278e4d61cb242/main/build/script.cjs#L27

Thank you. It's useful when I add externals like ['electron', 'uiohook-napi', 'electron-overlay-window'] in webpack.renderer.config.ts

focus-sc commented 1 year ago

I have a new problem. I used externals: ['uiohook-napi'] in webpack.config.ts, It's useful to run a develop project. But It's got error when I used electron-forge make to build a production project. what should I do to config the project? Thank you very much. _Uncaught Exception: Error: Cannot find module 'uiohook-napi' Require stack:

image

prevzzy commented 4 months ago

I ran into this issue using electron-overlay-window.

As in @focus-sc's case, adding externals: ['electron-overlay-window'] to my webpack config indeed did help, but only for the development process. When trying to build the app, using electron-forge make, I always ended up with "Cannot find module "electron-overlay-window"" error on application launch.

What helped me was using @timfish/forge-externals-plugin and adding the following to forge.config.js:

plugins: [
    ...,
    new ForgeExternalsPlugin({
      externals: ['electron-overlay-window'],
    })
  ],