rebuild icon indicating copy to clipboard operation
rebuild copied to clipboard

How can I tell electron-rebuild to ignore my library?

Open Julusian opened this issue 1 year ago • 4 comments

I have some libraries which provide node-api prebuilds for all common platforms. This means that electron-rebuild should almost never need to rebuild my library.
Rebuilding it forces users to spend more time waiting for the rebuild to happen, and can require them to install some dependencies/tools for the rebuild to succeed. (In one, there is an optional tool that if available will produce a more performant binary).

So ultimately, the forced rebuild is hurting users, with little/no benefit.
Is there either:

  • A way I can mark my library as not needing to be rebuilt? Perhaps a flag I should be setting in the package.json?
  • A way that users can tell electron-rebuild to ignore my library? They could use --only to do this, but it would be much better to be able to ignore a specific dependency instead of having to name all but one explicitly

Julusian avatar Dec 08 '22 12:12 Julusian

I think in general @electron/rebuild can be smarter around napi binaries. The problem is it's quite hardly to safely know if the native module is truly an napi module, I've seen some napi modules that still for whatever reason call nan or v8 methods directly 🙃

Do you have a ref to your module? Would probs help someone look into this with a "repro case"

MarshallOfSound avatar Dec 08 '22 18:12 MarshallOfSound

Ideally I should be able to put something in my package.json which says 'Im node-api, trust me'. If I was to do that and still use nan or v8 or something, then its clearly a bug in my library.
But I am not sure if this will be good enough for platforms where I don't provide prebuilds, which could be an issue in some scenarios.

I think electron-builder approaches this by invoking the install script for the package (with some env variables set to tell it to run for another target), under the assumption that a library will need to use that script to ensure it has an appropriate binary.


This came out of https://github.com/Julusian/node-midi, from a user issue, which includes a reproduction https://github.com/navelpluisje/midi-electron-test.

On ubuntu/debian, building the module requires the libasound2-dev package to be installed.

Another example which I assume will also be rebuilt, (I haven't verified) is https://github.com/julusian/node-jpeg-turbo. Which uses a tool yasm to process some assembly as part of the compilation. If that tool was not found it will fallback to c implementations, costing performance.

Julusian avatar Dec 08 '22 19:12 Julusian

I think in general @electron/rebuild can be smarter around napi binaries. The problem is it's quite hardly to safely know if the native module is truly an napi module, I've seen some napi modules that still for whatever reason call nan or v8 methods directly 🙃

Do you have a ref to your module? Would probs help someone look into this with a "repro case"

Yeah , such as level, It has prebuild binary, don`t need rebuild on pack;On my project , rebuild failed , Appreciate if you can take a look classic-level rebuild failed

rosendolu avatar Sep 14 '23 07:09 rosendolu

I have some libraries which provide node-api prebuilds for all common platforms. This means that electron-rebuild should almost never need to rebuild my library. Rebuilding it forces users to spend more time waiting for the rebuild to happen, and can require them to install some dependencies/tools for the rebuild to succeed. (In one, there is an optional tool that if available will produce a more performant binary).

So ultimately, the forced rebuild is hurting users, with little/no benefit. Is there either:

  • A way I can mark my library as not needing to be rebuilt? Perhaps a flag I should be setting in the package.json?
  • A way that users can tell electron-rebuild to ignore my library? They could use --only to do this, but it would be much better to be able to ignore a specific dependency instead of having to name all but one explicitly

I checked the doc, maybe below can help. add below in forge.config.js

rebuildConfig: {
    onlyModules: [],
  },

rosendolu avatar Sep 14 '23 07:09 rosendolu