This kind of error can happen when you are including native modules in your application. Native modules require compilation against the OS-specific node that your app is built on. So, while you are compressing to ASAR, you must exclude any native modules that are in your project. This is done with the unpackDir option inside of the 'asar' option on your overall packager options. For example, in my gulp build I do something like this:
var gulp = require('gulp');
var $ = require('gulp-load-plugins')({lazy: true});
var config = require('./gulp.config')();
var packager = require('electron-packager');
var electronPackage = require('electron/package.json');
var electronVersion = electronPackage.version;
var pkg = require('./package.json');
// Build the electron app
gulp.task('build:electron', function(cb) {
var opts = {
name: pkg.name,
platform: 'win32',
arch: 'ia32', // ia32, x64 or all
dir: config.root, // source location of app
out: config.electronbuild, // destination location for app os/native binaries
ignore: config.electronignore, // don't include these directories in the electron app build
icon: config.icon,
asar: {unpackDir: config.electroncompiled}, // compress project/modules into an asar blob but don't use asar to pack the native compiled modules
overwrite: true,
prune: true,
electronVersion: electronVersion, // Tell the packager what version of electron to build with
'app-copyright': pkg.copyright, // copyright info
'app-version': pkg.version, // The version of the application we are building
win32metadata: { // Windows Only config data
CompanyName: pkg.authors,
ProductName: pkg.name,
FileDescription: pkg.description,
OriginalFilename: pkg.name + '.exe'
}
};
packager(opts, function(err, appPath) {
$.util.log(' <- packagerDone()', err, appPath);
log(' all done!');
cb();
});
});
What is important for your case is the line for the asar option. You want to be sure that you do something like asar: {unpackDir: config.electroncompiled}
, and simply replace the config.electroncompiled
variable with your file glob of directories that include any natively compiled packages that your project uses (such things as libxml-xsd
, libxmljs-mt
, nslog
etc). Hope that makes sense.