Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node addon is not getting linked in the final packaged app #5932

Closed
robosushie opened this issue May 31, 2021 · 6 comments
Closed

node addon is not getting linked in the final packaged app #5932

robosushie opened this issue May 31, 2021 · 6 comments

Comments

@robosushie
Copy link

Using electron-builder version ^22.10.5 Using electron version ^13.0.1 -NA- platform=win32 arch=x64

I have built an application using electron where I have added native Cpp functionality. The front end part is using react and I am using a webpack script that continuously watches for the changes in the react files

"watch": "webpack --config webpack.renderer.js --watch",

and generate a compiled version of the react files into a compiled_renderer.js. I am then adding directly to the HTML file as a script.

<script src="./compiled/compiled_renderer.js"></script>

My electron-builder script which I am using and the basic build configuration is

"dist": "npm run clean && electron-builder && electron-builder install-app-deps",

"build": {
"appId": "com.example.boxrf",
"nodeGypRebuild": true,
"asar": true
},

I am adding the node addon to my project using the bindings library

const addon = require('bindings')('libsdr');

On running the built app on the laptop where I have but the app, I am getting this error.

image

So I modified the code and added the addon .node file in a separate directory and hardcoded the file path in my js file instead of using bindings.

"build": {
"appId": "com.example.boxrf",
"nodeGypRebuild": true,
"asar": true,
"extraFiles": [
{
"from": "build/Release",
"to": "resources/node.addon",
"filter": "*.node"
}
]
},

const addon = require('../../node.addon/libsdr.node');

In this scenario I am able to run the built application on my personal laptop but when I take the entire folder on another computer and run the app or install the app using the setup and then try to run the application. It is giving the error that the .node file is not found, although the path which it is trying to reference is the correct path and it contains the node addon file.

image

Whereas the file does exist in the given location

image

Any help would be appreciated. Thanks

@mmaietta
Copy link
Collaborator

Let's not go down the hardcoded path right now since that's a separate issue/error message.

bindings module should have just done the trick if you're packaging it correctly, and I see you're attempting to run it from the win-unpacked folder. Can you double check that your .node file is indeed at one of the file paths it specified?
I think I see an issue as your paths are within app.asar and I was under the impression that .node files all had to be unpacked, such as via:

    "asarUnpack": [
      "*.node"
    ]

@robosushie
Copy link
Author

@mmaietta
The file exist in the path. So if you see the path mentioned in the error \?\C:\Users.....libsdr.node ( I am confused with the \?\ portion is it causing any issue )

I tried asar unpack also, I have been keeping two different projects, with the exact same contents. One I have built using electron-builder, another using electron-forge. I tried unpacking the .node files in both my setups but it is not working. Link

@robosushie
Copy link
Author

@mmaietta
I saw one of your comments in another similar issue. (Link)

I am not able to get the "awesome-node-loader" part and the "!packDistributable", is there any github repo which I can refer to?

@mmaietta
Copy link
Collaborator

mmaietta commented Jun 1, 2021

packDistributable simply is a local var I use to discern whether we should be bundling for a distribution build (i.e. packed electron app) versus running locally via electron .

For the loader: https://github.com/gurisko/awesome-node-loader. This is the magic it's flipping between:

This option chooses in between __dirname and path.dirname(process.execPath)

Basically, I couldn't use __dirname in the prod distributable and I placed all .node addons at the app root (/ for win/linux and /Contents/MacOS for mac)
I can't link the repo though because it's my company's internal project

@stale
Copy link

stale bot commented Jul 31, 2021

Is this still relevant? If so, what is blocking it? Is there anything you can do to help move it forward?

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs.

@stale stale bot added the backlog label Jul 31, 2021
@stale stale bot closed this as completed Sep 22, 2021
@knaos
Copy link

knaos commented Dec 7, 2021

I am having a common issue, though it seems electron related, because I am running the app in dev mode. When I am trying to load a NativeModule.node but the current working directory (cwd) is different than the one where the app is, the module is not loaded even though the path is absolute and correct. This happens when for example the application is run from windows startup.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants