Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-1251

Prebuilt binaries aren't fetched when packaging an Electron app

    • Type: Icon: Bug Bug
    • Resolution: Done
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: Q3-24FY
    • Component/s: Electron

      Goals

      Using electron-builder to install native dependencies for an Electron app using Realm JS for Windows or Linux on a macOS machine.

      Expected Results

      I expect Electron Builder to recognise Realm JS as having a native module which needs to be installed using prebuild-install.

      Actual Results

      When building for Windows on a macOS machine, end users of the electron app experience the following error:

      Uncaught Error: \\?\C:\Users\bimusiek\AppData\Local\Temp\3da4c319-5a47-4f25-9b04-8a36075b8f09.tmp.node is not a valid Win32 application.
      

      This is because the realm.node binary shipped with the Windows build is actually the binary for macOS which never got replaced when the app was being packaged.

      A temporary fix we needed in Realm Studio was this line:

      touch node_modules/realm/binding.gyp
      

      My investigations this far concludes: Electron Builder (the electron-builder package on NPM) looks for (at least) the binding.gyp file when determining if a dependency of an electron app has a native module or not. As a consequence Electron builder won't fetch the correct prebuilds when building the app for Windows nor Linux on a macOS machine. The binding.gyp file was removed as we migrated Realm JS to cmake-js.

      We could add the empty file to our package, but since that feels a bit like a workaround, I would love to learn of alternative ways to tell electron-builder to consider Realm JS as having native modules which needs to be fetched when packaging up the app.

      This could be related to https://github.com/electron/electron-rebuild/issues/268.

      Steps to Reproduce

      • Initialize an NPM package with electron@11.2.1, realm@10.5.0 and electron-builder@22.10.5.
      • Try adding native dependencies (npx electron-builder install-app-deps)
      • Notice that realm is not included.
      • Add the binding.gyp file to Realm JS (touch node_modules/realm/binding.gyp)
      • Try adding native dependencies again and notice that realm appears.

      Version of Realm and Tooling

      • Realm JS SDK Version: 10.5.0
      • Node or React Native: Electron
      • Client OS & Version: Tested on MacOS
      • Which debugger for React Native: N/A

            Assignee:
            kraen.hansen@mongodb.com Kræn Hansen
            Reporter:
            kraen.hansen@mongodb.com Kræn Hansen
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: