capacitor-community / electron

Deploy your Capacitor apps to Linux, Mac, and Windows desktops, with the Electron platform! 🖥️
https://capacitor-community.github.io/electron/
MIT License
335 stars 59 forks source link

Error when adding electron plugin to capacitor project - (npx cap add @capacitor-community/electron) #188

Closed macsupport closed 2 years ago

macsupport commented 2 years ago

Describe the bug After installing Electron npm i @capacitor-community/electron, adding electron usingnpx cap add @capacitor-community/electron, shows the following error:

npx cap add @capacitor-community/electron
ℹ Adding Electron platform: start 🚀
ℹ Adding Electron platform: extracting template
ℹ Adding Electron platform: copying capacitor config file
ℹ Adding Electron platform: setting up electron project
✖ Adding Electron platform: 
node:internal/process/promises:265
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[UnhandledPromiseRejection: This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason "
> fsevents@2.3.2 install /Users/macsupport/Downloads/core/electron/node_modules/chokidar/node_modules/fsevents
> node-gyp rebuild

> node-addon-api@3.2.1 install /Users/macsupport/Downloads/core/electron/node_modules/electron-rebuild/node_modules/lzma-native/node_modules/node-addon-api
> node-gyp rebuild

> electron@14.2.9 postinstall /Users/macsupport/Downloads/core/electron/node_modules/electron
> node install.js

npm WARN package.json Vetcalculators@1.0.0 No README data
gyp: binding.gyp not found (cwd: /Users/macsupport/Downloads/core/electron/node_modules/chokidar/node_modules/fsevents) while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:261:16)
gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 21.4.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/macsupport/Downloads/core/electron/node_modules/chokidar/node_modules/fsevents
gyp ERR! node -v v16.14.0
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok 
npm WARN optional dep failed, continuing fsevents@2.3.2
npm WARN deprecated dmg-license@1.0.11: Disk image license agreements are deprecated by Apple and will probably be removed in a future macOS release. Discussion at: https://github.com/argv-minus-one/dmg-license/issues/11
npm WARN engine smart-buffer@4.2.0: wanted: {"node":">= 6.0.0","npm":">= 3.0.0"} (current: {"node":"16.14.0","npm":"2.15.12"})
gyp: binding.gyp not found (cwd: /Users/macsupport/Downloads/core/electron/node_modules/electron-rebuild/node_modules/lzma-native/node_modules/node-addon-api) while trying to load binding.gyp
gyp ERR! configure error 
gyp ERR! stack Error: `gyp` failed with exit code: 1
gyp ERR! stack     at ChildProcess.onCpExit (/usr/local/lib/node_modules/node-gyp/lib/configure.js:261:16)
gyp ERR! stack     at ChildProcess.emit (node:events:520:28)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (node:internal/child_process:291:12)
gyp ERR! System Darwin 21.4.0
gyp ERR! command "/usr/local/bin/node" "/usr/local/lib/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/macsupport/Downloads/core/electron/node_modules/electron-rebuild/node_modules/lzma-native/node_modules/node-addon-api
gyp ERR! node -v v16.14.0
gyp ERR! node-gyp -v v9.0.0
gyp ERR! not ok 
npm WARN engine socks@2.6.2: wanted: {"node":">= 10.13.0","npm":">= 3.0.0"} (current: {"node":"16.14.0","npm":"2.15.12"})
npm WARN engine smart-buffer@4.2.0: wanted: {"node":">= 6.0.0","npm":">= 3.0.0"} (current: {"node":"16.14.0","npm":"2.15.12"})
npm ERR! Darwin 21.4.0
npm ERR! argv "/usr/local/bin/node" "/Users/macsupport/node_modules/.bin/npm" "i"
npm ERR! node v16.14.0
npm ERR! npm  v2.15.12
npm ERR! code ELIFECYCLE

npm ERR! node-addon-api@3.2.1 install: `node-gyp rebuild`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the node-addon-api@3.2.1 install script 'node-gyp rebuild'.
npm ERR! This is most likely a problem with the node-addon-api package,
npm ERR! not with npm itself.
npm ERR! Tell the author that this fails on your system:
npm ERR!     node-gyp rebuild
npm ERR! You can get information on how to open an issue for this project with:
npm ERR!     npm bugs node-addon-api
npm ERR! Or if that isn't available, you can get their info via:
npm ERR! 
npm ERR!     npm owner ls node-addon-api
npm ERR! There is likely additional logging output above.

npm ERR! Please include the following file with any support request:
npm ERR!     /Users/macsupport/Downloads/core/electron/npm-debug.log
".] {
  code: 'ERR_UNHANDLED_REJECTION'
}

To Reproduce run npx cap add @capacitor-community/electron

Expected behavior Electron should be added without this error

aakatheeri commented 2 years ago

I have the same problem when I tried to install the plugin. Any solution for this?

IT-MikeS commented 2 years ago

This is typically an issue with your node installation. Give both node 16.x+ and npm 8.x+ a re-install.

macsupport commented 2 years ago

Unfortunately, I did that a number of times with no change.

IT-MikeS commented 2 years ago

The error posted points to npm being very out of date, there may be something wrong with what version is being used. If you use tools like nvm make sure those are functioning properly.

macsupport commented 2 years ago

For anyone with this issue in the future. It seems I had another, old version of npm in my Users/myname/ folder, which was being utilized instead of the global, current npm version.