node.jsnpmelectronnode-gyp

Compile node module with node-gyp for a specific NODE_MODULE_VERSION


I am trying to use an npm package fsuipc in an electron app. However, when I start the app I get the following error

The module 'node_modules\fsuipc\build\Release\fsuipc.node'
was compiled against a different Node.js version using
NODE_MODULE_VERSION 93. This version of Node.js requires
NODE_MODULE_VERSION 98.

I am trying to recompile it for version 98. I have 0 experience with node-gyp or similar, I just want it to work :(. I have tried doing node-gyp build --target=v16.13.1 but it still compiles to this mysterious version 93 which I can't seem to change. Any help is appreciated.


Solution

  • After two days of research and endless trial and error I have found a solution.

    This may have been an error in the electron boiler plate that I was using but the bottom line is that I had to manually build the native package. From here I learned that I was compiling it using my current node.js version installed but because I was using electron it required building the module with electron headers. The steps I followed were these:

    1. cd release/app && npm install fsuipc Native dependencies have to be installed in release/app.
    2. cd node_modules/fsuipc && npm install Move to the package dir and install its required dependencies for building.
    3. node-gyp rebuild --target=15.3.5 --arch=x64 --dist-url=https://electronjs.org/headers This was the key. The target has to be the VALID and FULL version name that you are using from this website (if you are using electron). From trial and error I solved some problems by specifying that I was building for x64. And in order for it to compile using electron specify the headers url (same for all electron versions).
    4. cd ../../ && npm install By calling install in the release/app directory the modules are linked with the "normal" node_modules

    Then just run!