question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unable to load native addon after electron-builder

See original GitHub issue
  • Version: 19.35.1
  • Target: Windows 10 x64

Hi all, I’m trying to package an Electron application with a custom native addon (i.e. written by me), and have been unsuccessful so far. The app builds, but when I run it, it’s unable to load the native module, and exits.

Running the app locally, with electron . works just fine, which leads me to believe that the native module has not been packaged with the executable.

My package.json looks like this:

{
  "build": {
    "appId": "App name",
    "productName": "App company",
    "copyright": "Copyright © 2017 App Inc.",
    "nsis": {},
    "win": {
      "target": "nsis"
    },
    "mac": {
      "target": "dmg"
    }
  },
  "scripts": {
    "pack": "electron-builder --dir",
    "dist": "electron-builder -w --x64 --ia32"
  },
  "postinstall": "electron-builder install-app-deps",
  "devDependencies": {
    "electron-builder": "^19.6.3"
  }
}

And the app directory structure like this:

application-root-dir
	-app
		-addon
			-build
				-Release
					-addon.node
				-addon.sln
		-node_modules
		-main.js
		-package.json
	-build
	-node_modules
	-package.json

Addon source code and MSVC project files, as well as *.node files are all in application-root-dir/app/addon/*

When I run npm run dist, I get the following output:

> electron-builder -w --x64 --ia32

electron-builder 19.35.1
No native production dependencies
Packaging for win32 x64 using electron 1.6.14 to dist\win-unpacked
No native production dependencies
Packaging for win32 ia32 using electron 1.6.14 to dist\win-ia32-unpacked
Building nsis installer (x64 and ia32)

So, everything seemingly builds just fine, and the app installs successfully, but when I try to run, it’s unable to load the native module (from main.js), and just exits. Below is the manner in which I load/require the module:

var addon

try {
  addon= worker (
    path.join(__dirname, './addon/build/Release/addon'), 
    {name: 'addon'}
  );
}
catch(err) {
  try {
    addon= worker (
      path.join(__dirname, './addon/build/Debug/addon'),
      {name: 'addon'}
    );
  }
  catch(err) {
    log.error('Unable to load addon, exiting app...')
    app.exit()
  }
}

Any help would be appreciated.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

2reactions
nikola-maticcommented, Oct 11, 2017

Settings "nodeGypRebuild":"true" in root package.json solved above issue.

1reaction
nikola-maticcommented, Aug 4, 2018

@Cprofessor3 unfortunately not; in the end, we moved away from electron and used CEF instead.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How do I load my own native node modules in my Electron app?
All other native modules which are located in node_modules/ and which contain a build/Release directory load totally fine. P.S. If I copy foo....
Read more >
electron-builder
A complete solution to package and build a ready for distribution Electron app for macOS, Windows and Linux with “auto update” support out...
Read more >
Native Node Modules | Electron
When in doubt, run electron-rebuild first. · Make sure the native module is compatible with the target platform and architecture for your Electron...
Read more >
electron builder not allowed to load local resource - You.com
I was not able to find any folder called dist packaged in the app.asar, ... After build: 'Not allowed to load local resource'...
Read more >
electron-builder | Yarn - Package Manager
A complete solution to package and build a ready for distribution Electron, Proton Native app for macOS, Windows and Linux with “auto update”...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found