EvenAR / node-simconnect

A cross platform SimConnect client library for Node.JS

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Issue rebuilding for Electron

dolbex opened this issue · comments

@EvenAR

First, thanks for your hard work on this. We would love to use this module for an electron sideproject a couple of us are working on but we're having a hell of a time getting it to work. We have tried building with electron-rebuild but we run into a bunch of errors like:

[path]\node_modules\node-simconnect\src\addon.cc(327,97): error C2661:
'v8::Object::Set': no overloaded function takes 2 arguments [path]\node_modules\node-simconnect\build\node-simconnect.vcxproj]

We can build using this method: #27 (comment)

However, then we get a warning about the module being built against a different version of NODE_MODULES than electron (something like version 73 vs version 76. Any ideas?

Did you try using this version/replacement file #12 (comment)

I have not but I will definitely take a look this evening and get back to this thread on how it works out. Thanks so much @BarryCarlyon!

Ok, sooooo, this totally worked for me. Here is my setup that I'm using for anyone that runs into this issue:

    "node-simconnect": "^1.4.1"
    "electron": "6.1.7",
    "electron-builder": "22.8.1",
    "electron-rebuild": "^2.3.5",

Replaced addon.cc in node-modules/node-simconnect/src/ with https://gist.github.com/westlakem/17910065569d21066d038667537e48ee
Copied my SimConnect folder over from the MSFS2020 SDK folder to node-modules/node-simconnect
Renamed include to inc
Ran electron-rebuild from the root of the project (not the node-simconnect folder)
Copied SimConnect.dll to the build/Release folder in node-simconnect

@dolbex, I might be a bit obtuse here, but I still can't get it to run, even after following either your or @EvenAR's step-by-step. Let me step-by-step it for other smooth brains out there. Am I doing it right?

  1. Install node-simconnect using npm install node-simconnect in the project folder.
  2. Replace addon.cc in node/modules/node-simconnect/src with the file mentioned above.
  3. Copy the two SimConnect SDK folders (lib and include) into /node-modules/node-simconnect/SimConnect/.
  4. Rename include to inc.
  5. Run electron-rebuild from the root folder (on windows, so I ran .\node_modules\.bin\electron-rebuild.cmd per https://github.com/electron/electron-rebuild. (this now passed some of the initial errors, just a few deprecation warnings left, which sounds like they are expected?)
  6. Copy SimConnect.dll to to build/Release/SimConnect.dll
  7. Ran app: get This relative module was not found: * ./bin/win_ia32/node-simconnect in ./node_modules/node-simconnect/index.js
  8. Follow @EvenAR's advice to remove relative paths. From: nodeSimconnect = require(./build/Release/node-simconnect); to nodeSimconnect = require(C:/Project/Name/node_modules/node-simconnect/build/Release/node-simconnect);
  9. Ran app. Get This relative module was not found * ./bin/win_ia32/node-simconnect in ./node_modules/node-simconnect/index.js.

Am I completely off on something here? I also tried running npx node-gyp configure rebuild --msvs_version=2019 --arch=x64 inside node-simconnect, but I end up with the same error. Even when --arch=x64......

Hey @bogdanrau - Sorry to hear that you're having problems. It took me about 48 hours to finally get it to ran and I almost gave up. Don't give up! (And you're not being obtuse at all - thanks for the details)

So, I can confirm that I was also on windows. I'm normally on Mac but given the project got to enjoy the wonders of development on Windows :)

Also, I can confirm that I definitely did not have your issue on step 7. Certainly, there is probably something I did during my 9000 attempts that I'm omitting that prevented that from happening but I have no idea what that could have been. However, my question is: If I'm remembering correctly, that /Release/node-simconnect is the prebuilt one, correct? (See lines 6 - 18) in index.js. Why would it be missing your manual build? (Maybe I'm misremembering here)

Hmm. So I do have a release/node-simconnect.node file in there, along with several others. Just no node-simconnect folder. Is this the desired outcome)? I assumed the require statements looked a file, not a folder.

@bogdanrau - I'm not in front of that computer at the moment but it looks for ./build/Release/node-simconnect and if that's not there it falls back to the catch and loads the prebuilt version which it looks like it's doing. Maybe throw some console.logs and see what it's doing / finding to confirm.

When you run electron-rebuild it should be building out your custom build.

Heres what I do

I use a mildly modified version of Westlakem's addon.cc from issue 12 that I linked earlier in this thread. (fixes a weirdness and I was working on extra functions and extra data, should probably throw up a repo)

On my Windows Computer/VM (just don't bother with native Mac, coz MSFS doesn't run on mac anyway, and network SimConnect is it's own mess)

  • Start powershell as admin
  • Run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
  • cd to myapp/node_modules/node-simconnect/
  • Copy the SimConnect folder into this folder
  • rename SinConnect/include to SimConnect/inc
  • run ../../../node_modules/.bin/electron-rebuild --force (path may vary, I use the double package.json approach for Electron Dev, if you don't you only need two ../)
  • copy SimConnect/lib/SimConnect.dll into build/Release

And that is what is working fine for me, both for testing the app and building the installer for others to download and use the app.

My last build was under

  • node v14.15.1
  • electron v11.2.3

I'm pretty sure you're going to have to roll back to "electron": "6.1.7"

I couldnt' get it to work with the latest electron. Also, not entirely sure what your doing with the rebuild but I just ran that from the root of the project using a package command that doesn't look like yours. Try adding this to your package.json and running yarn rebuild (or npm if that's your flavor)

"rebuild": "electron-rebuild -f -w node-simconnect"

@dolbex is your "rollback" suggestion aimed at me? As it's fine for me under electron 11.2.3, I just updated to electron 11.3.0 and rebuilt fine and retested.

image

image

(fails to connect to sim as I didn't open the sim for this test)
(Red censors a connection key for something else)

Oh, sorry @BarryCarlyon - Its nuts at work and I should have been paying better attention. Glad to hear you have it running in the latest and greatest - I'll definitely attempt upgrading mine.

Also, can you post your modified addon.cc?

Did you try using this version/replacement file #12 (comment)

@BarryCarlyon do you mind sharing a gist for your version of the file? That would be great!

Did you try using this version/replacement file #12 (comment)

@riccardolardi I'm using (essentially) the one from 12

So not sure what you need/want

I have some extra edits for some other bits but nothing directly related to electron building the module

Heres what I do

I use a mildly modified version of Westlakem's addon.cc from issue 12 that I linked earlier in this thread. (fixes a weirdness and I was working on extra functions and extra data, should probably throw up a repo)

On my Windows Computer/VM (just don't bother with native Mac, coz MSFS doesn't run on mac anyway, and network SimConnect is it's own mess)

  • Start powershell as admin
  • Run Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
  • cd to myapp/node_modules/node-simconnect/
  • Copy the SimConnect folder into this folder
  • rename SinConnect/include to SimConnect/inc
  • run ../../../node_modules/.bin/electron-rebuild --force (path may vary, I use the double package.json approach for Electron Dev, if you don't you only need two ../)
  • copy SimConnect/lib/SimConnect.dll into build/Release

And that is what is working fine for me, both for testing the app and building the installer for others to download and use the app.

My last build was under

  • node v14.15.1
  • electron v11.2.3

I can confirm this approach worked for me too. I can build successfully even under x64

Ok, sooooo, this totally worked for me. Here is my setup that I'm using for anyone that runs into this issue:

    "node-simconnect": "^1.4.1"
    "electron": "6.1.7",
    "electron-builder": "22.8.1",
    "electron-rebuild": "^2.3.5",

Replaced addon.cc in node-modules/node-simconnect/src/ with https://gist.github.com/westlakem/17910065569d21066d038667537e48ee Copied my SimConnect folder over from the MSFS2020 SDK folder to node-modules/node-simconnect Renamed include to inc Ran electron-rebuild from the root of the project (not the node-simconnect folder) Copied SimConnect.dll to the build/Release folder in node-simconnect

god, this is the key!!!!!!

Thanks to everyone helping each other out!

I'm closing this thread as the new version does not require a custom build to work with Electron.