I am building a project that works well when I have ASAR turned off. The build is good and everything executes as expected. Here's my code for doing the build:
var packager = require('electron-packager');
var pkg = require('./package.json');
var electronPackage = require('electron-prebuilt/package.json');
var electronVersion = electronPackage.version;
var opts = {
name: pkg.name,
platform: 'win32',
arch: 'x64',
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: false, // compress the entire source in an asar/zip blob
overwrite: true,
version: 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
'version-string': { // Windows Only config data
CompanyName: pkg.authors,
ProductName: pkg.name,
FileDescription: pkg.description,
OriginalFilename: pkg.name + '.exe'
}
};
// Build the electron app
gulp.task('build:electron', function() {
$.util.log('Launching task to build & package binaries for',
$.util.colors.cyan(opts.name),
$.util.colors.magenta('v' + opts['app-version'])
);
packager(opts, function(err, appPath) {
$.util.log(' <- packagerDone()', err, appPath);
log(' all done!');
});
});
But if I take the same build and use the ASAR option (I am calling it from gulp), then the application throws an error at start up. I've attached a screen shot here.

Because I am really needing to get this to work with ASAR on, I went into the bindings.js file (the module reporting the exception) and wrote some trace data to a log file to see which module was not being found. Turns out, it was :
app.asar\node_modules\libxml-xsd\build\Release\node-libxml-xsd.node
which is a node module that requires recompile when you use electron. As I said, this works fine when it is NOT in ASAR packed format. So I know the binary is ok.
I was trying to understand why the bindings module thought that particular file /module wasn't in the ASAR and I decided to ask ASAR (the command) what was inside of app.asar to be sure the files were actually packed in it. I did the following command :
asar list app.asar
deep in the results, it does in fact think the module is there:
\node_modules\libxml-xsd
\node_modules\libxml-xsd.npmignore
.. .. .. ..
.. .. .. ..
\node_modules\libxml-xsd\build\Release
\node_modules\libxml-xsd\build\Release\node-libxml-xsd.exp
\node_modules\libxml-xsd\build\Release\node-libxml-xsd.lib
\node_modules\libxml-xsd\build\Release\node-libxml-xsd.map
\node_modules\libxml-xsd\build\Release\node-libxml-xsd.node
.. .. .. ..
.. .. .. ..
Now I don't know how to actually understand ASAR contents beyond using the ASAR command to do a list. So I couldn't investigate further.
Again, I can get this entire build working with ASAR option turned off, but when it is on, this module appears to fail.
Which version of electron-packager are you using?
"electron-packager": "7.2.0",
What CLI arguments are you passing? Alternatively, if you are using the API, what parameters are
you passing to thepackager()function?
See above code
What version of Electron are you building with?
"electron-prebuilt": "1.2.6",
What is the host platform are you running electron-packager on?
I am running this on Windows 7 win32 arch with x64 bit
What target platform(s)/architecture(s) are you building for?
win32 arch with x64 bit
Is there a stack trace in the error message you're seeing?
see attached image
Please provide either a failing testcase or detailed steps to reproduce your problem.
Provided above...
I think you need to use either the asar-unpack or asar-unpack-dir parameters on the folders containing native modules.
Thank you... I am still finding my way around on this stuff.. since I am using gulp (not command line), how would I use a glob pattern to list multiple directories (I think there are a couple other native modules I will need to keep unpacked). For example, practically speaking I need to do exclude 3 modules (libxml-xsd, libxmljs-mt and nslog). I am familiar with regex, but glob is new to me. How would I do something like:
'node_modules/(libxml-xsd|libxmljs-mt|nslog)',
or can the 'asar-unpack-dir' take an array?
Looks like it only takes one string, see the API docs for asar-unpack-dir for glob examples.
(The one string limitation appears to be an asar module limitation, if you think it should work as an array, you'd need to file an issue in their repository.)
wow. Thanks so much for the helpful response. Really appreciate that.
Most helpful comment
I think you need to use either the
asar-unpackorasar-unpack-dirparameters on the folders containing native modules.