electron / forge

:electron: A complete tool for building and publishing Electron applications
https://electronforge.io
MIT License
6.49k stars 516 forks source link

node-gyp failed to rebuild #3272

Open DoneDeal0 opened 1 year ago

DoneDeal0 commented 1 year ago

Pre-flight checklist

Electron Forge version

6.2.1

Electron version

25.2.0

Operating system

macOS 13.4.1

Last known working Electron Forge version

No response

Expected behavior

The app should compile.

Actual behavior

The electron app doesn't compile properly. Here is the complete log:

> electron-forge start

✔ Checking your system
✔ Locating application
✔ Loading configuration
✖ Preparing native dependencies: 0 / 1
  › node-gyp failed to rebuild '/Users/myname/Desktop/myapp/node_modules/ca…
◼ Running generateAssets hook

› Package 'gobject-2.0' requires 'libffi >= 3.0.0' but version of libffi is 2.1
  Package 'gobject-2.0' requires 'libffi >= 3.0.0' but version of libffi is 2.1
  SOLINK_MODULE(target) Release/canvas-postbuild.node
  CXX(target) Release/obj.target/canvas/src/backend/Backend.o
  In file included from ../src/backend/Backend.cc:1:
  ../src/backend/Backend.h:3:10: fatal error: 'cairo.h' file not found
  #include <cairo.h>
  ^~~~~~~~~
  1 error generated.
  make: *** [Release/obj.target/canvas/src/backend/Backend.o] Error 1
  Error: `make` failed with exit code: 2
  at ChildProcess.onExit (/Users/myname/Desktop/myapp/node_modules/node-gyp…
  at ChildProcess.emit (node:events:513:28)
  at ChildProcess._handle.onexit (node:internal/child_process:291:12)

An unhandled rejection has occurred inside Forge:
Error: node-gyp failed to rebuild '/Users/myname/Desktop/myapp/node_modules/canvas'
at ChildProcess.<anonymous> (/Users/myname/Desktop/myapp/node_modules/@electron/rebuild/lib/module-type/node-gyp/node-gyp.js:118:24)
    at ChildProcess.emit (node:events:513:28)
    at ChildProcess._handle.onexit (node:internal/child_process:291:12)

Steps to reproduce

I have the latest version of Electron and associated lib. The app works fine on macOS Big Sure, but not on macOS Ventura.

Do I need to globally install a package like node-gyp to make it work?

Additional information

No response

erickzhao commented 1 year ago

@DoneDeal0 Sorry for the delayed response. Do you have an exact repro available? This seems like an issue with the native module you're using but I'd like to confirm the setup on my end as well.

DoneDeal0 commented 1 year ago

@erickzhao here is a basic repo: https://github.com/DoneDeal0/electron-build-fail

If I remove it, the build works fine. Unfortunately, I need this lib.

I have node 18.16.1. The build fails on a machine with an I7 chip, but works fine on an M2 machine. This is very strange. The PDFJS team won't help me because I use their lib in Electron.

DoneDeal0 commented 1 year ago

@erickzhao hi, have you had time to research this issue?

cqtangsong commented 9 months ago

i have a Similar question

electron-forge make

✔ Checking your system rget/fse/fsevents.o In file included from ../fsevents.cc:6: ../../../../nan/nan.h:688:39: warning: 'IdleNotificationDeadline' is deprecated: Use… return v8::Isolate::GetCurrent()->IdleNotificationDeadline( ^ /Users/tangsong/.electron-gyp/28.1.4/include/node/v8-isolate.h:1343:3: note: 'IdleNo… V8_DEPRECATE_SOON( ^ /Users/tangsong/.electron-gyp/28.1.4/include/node/v8config.h:561:41: note: expanded …

define V8_DEPRECATE_SOON(message) [[deprecated(message)]]

^ ../fsevents.cc:14:10: fatal error: 'src/storage.cc' file not found

include "src/storage.cc"

^~~~ 1 warning and 1 error generated. make: *** [Release/obj.target/fse/fsevents.o] Error 1 Error: make failed with exit code: 2 at ChildProcess.onExit (/Users/tangsong/Documents/cqq/test/demo/node_modules/node-gy… at ChildProcess.emit (node:events:513:28) at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)

An unhandled rejection has occurred inside Forge: Error: node-gyp failed to rebuild '/private/var/folders/6c/44_3vj9n74sdtr04s4nndkr40000gp/T/electron-packager/tmp-JTs2GE/Electron.app/Contents/Resources/app/node_modules/watchpack-chokidar2/node_modules/fsevents' at ChildProcess. (/Users/tangsong/Documents/cqq/test/demo/node_modules/@electron/rebuild/lib/module-type/node-gyp/node-gyp.js:118:24) at ChildProcess.emit (node:events:513:28) at Process.ChildProcess._handle.onexit (node:internal/child_process:293:12)

Brown000 commented 8 months ago

Same problem for me when I installed ssh2 in my electron forge project. Node-gyp can not rebuild cpu-features which is one of the dependencies of ssh2. The environment info is: cpu: M1 Pro os: MacOS 14.3.1 node: v18.18.0 electron: ^29.0.1 electron-forge: ^7.3.0 ssh2: ^1.15.0

Brown000 commented 8 months ago

Same problem for me when I installed ssh2 in my electron forge project. Node-gyp can not rebuild cpu-features which is one of the dependencies of ssh2. The environment info is: cpu: M1 Pro os: MacOS 14.3.1 node: v18.18.0 electron: ^29.0.1 electron-forge: ^7.3.0 ssh2: ^1.15.0

For this problem, I found ssh2-electron-no-cpu-features which do not need cpu-features dependency. And this worked for me. If you using typescript, you can just install @types/ssh2 and rename node_modules/@types/ssh2 to ssh2-electron-no-cpu-features, then you can have fully annotations. Wish this can help you if you have same problem.

sesh92 commented 2 months ago

1) Open your lock file 2) Find the ssh2's dependencies, you can see the cpu-features is optional, just drop this dependency from there. my case looks like:

"ssh2@npm:^1.5.0":
  version: 1.5.0
  resolution: "ssh2@npm:1.5.0"
  dependencies:
    asn1: ^0.2.4
    bcrypt-pbkdf: ^1.0.2
-   cpu-features: 0.0.2
-   nan: ^2.15.0
  dependenciesMeta:
    cpu-features:
      optional: true
    nan:
      optional: true
      ... 

3) reinstall deps