packager: Maximum call stack size exceeded when asar is enabled

  • [x ] I have read the contribution documentation for this project.
  • [x ] I agree to follow the code of conduct that this project follows, as appropriate.
  • [x ] I have searched the issue tracker for an issue that matches the one I want to file, without success.

Main ISSUE:

It appears that electron-packager (npm --prune) is failing when it is trying to delete temporary files (ie. C:\Users\MyUser\AppData\Local\Temp\electron-packager.… etc ).

Secondary ISSUE:

As the instructions for debugging and submitting issues state, I turned on ‘DEBUG=electron-packager’ environment variable to get pertinent information on the problem. This, however, produced exceeding different results, which you will see below.

Console output when you run electron-packager with the environment variable DEBUG=electron-packager. Please include the stack trace if one exists.

IMPORTANT NOTE: The output was significantly different depending on whether I used the DEBUG setting or not. Both output streams are shown below.

CONSOLE OUTPUT A (with DEBUG)

If I turn on the DEBUG=electron-packager environment variable, I get different results, as follows:

C:\git\my-application>gulp build:electron
[15:32:57] Using gulpfile C:\git\my-application\gulpfile.js
[15:32:57] Starting 'build:electron'...
[15:32:57] Launching task to build & package binaries for MyApplication v0.1.10
  electron-packager Electron Packager 9.1.0 +0ms
  electron-packager Node v8.5.0 +1ms
  electron-packager Host Operating system: win32 (x64) +0ms
  electron-packager Packager Options: {"name":"MyApplication","platform":"win32","arch":"x64","dir":"./","out":"./edist/","ignore":[{},{},{},{},{},{},{},{},{}],"icon":"./ClientSide/app/images/icons/translator.ico","asar":{"unpackDir":"node_modules/
{libxml-xsd,libxmljs-mt,nslog}/**/*"},"overwrite":true,"prune":true,"electronVersion":"1.7.7","appCopyright":"Copyright (C) My Company Technologies, Inc. All Rights Reserved","appVersion":"0.1.10","win32metadata":{"CompanyName":["My Application Team"],"ProductName":"MyApplication","FileDescription":"My Application Project Translator","OriginalFilename":"MyApplication.exe"}} +0ms
  electron-packager Target Platforms: win32 +1ms
  electron-packager Target Architectures: x64 +0ms
  electron-packager Application name: MyApplication +0ms
  electron-packager Target Electron version: 1.7.7 +1ms
  electron-packager Ignored path regular expressions: [ /\/\.idea$/,
  /\/\b(ci|ClientSide|WiXInstaller|loaders|edist|ExternalStyles)$/,
  /\/\b(ServerSide\/test)$/,
  /(\.htmlhintrc|\.jscsrrc|\.jshintrc|.stylelintrc|tslint\.json)$/,
  /(gulp\.config\.js|gulpfile\.js)$/,
  /(karma\.conf\.js|karmaBase\.conf\.js|karmaDebug\.conf\.js)$/,
  /(webpack\.config\.js|webpack\.testConfig\.js|webpack\.UnittestConfig\.js|webpackBase\.config\.js)$/,
  /(tsconfig\.json)$/,
  /(\.gitignore|README\.md)$/,
  '/node_modules/electron($|/)',
  '/node_modules/electron-prebuilt(-compile)?($|/)',
  '/node_modules/electron-packager($|/)',
  '/\\.git($|/)',
  '/node_modules/\\.bin($|/)',
  '\\.o(bj)?$' ] +0ms
  electron-packager Downloading Electron with options {"platform":"win32","arch":"x64","version":"1.7.7"} +0ms
Packaging app for platform win32 x64 using electron v1.7.7
  electron-packager Creating C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64-template +2s
  electron-packager Extracting C:\Users\MyUser\.electron\electron-v1.7.7-win32-x64.zip to C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64-template +2ms
  electron-packager Initializing app in C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64\MyApplication-win32-x64 from C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64-template template +2s
  electron-packager Ignored paths based on the out param: [ 'C:\\git\\my-application\\edist' ] +3s
  electron-packager Pruning modules via: npm prune --production +0ms
  electron-packager Running asar with the options {"unpackDir":"node_modules/{libxml-xsd,libxmljs-mt,nslog}/**/*"} +1m
C:\git\my-application\node_modules\asar\lib\disk.js:33
      return callback(error)
             ^

RangeError: Maximum call stack size exceeded
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:33:14)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)
    at writeFileListToStream (C:\git\my-application\node_modules\asar\lib\disk.js:35:12)

C:\git\my-application>

CONSOLE OUTPUT A (without DEBUG)

If I remove DEBUG=electron-packager environment variable, I get the results as follows:

C:\git\my-application>gulp build:electron
[14:13:49] Using gulpfile C:\git\my-application\gulpfile.js
[14:13:49] Starting 'build:electron'...
[14:13:49] Launching task to build & package binaries for MyApplication v0.1.10
Packaging app for platform win32 x64 using electron v1.7.7
[14:15:17] 'build:electron' errored after 1.47 min
[14:15:17] Error: Command failed: npm prune --production
npm ERR! May not delete: C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64\MyApplication-win32-x64\resources\app\node_modules\.bin

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\MyUser\AppData\Roaming\npm-cache\_logs\2017-09-20T21_15_17_397Z-debug.log

    at ChildProcess.exithandler (child_process.js:270:12)
    at emitTwo (events.js:125:13)
    at ChildProcess.emit (events.js:213:7)
    at maybeClose (internal/child_process.js:927:16)
    at Socket.stream.socket.on (internal/child_process.js:348:11)
    at emitOne (events.js:115:13)
    at Socket.emit (events.js:210:7)
    at Pipe._handle.close [as _onclose] (net.js:545:12)

C:\git\my-application>

extracting the pertinent lines from the recommended log file shows the following :

5857 verbose unlock done using C:\Users\MyUser\AppData\Roaming\npm-cache\_locks\staging-0d81affe015dbade.lock for C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64\MyApplication-win32-x64\resources\app\node_modules\.staging
5858 verbose stack Error: May not delete: C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64\MyApplication-win32-x64\resources\app\node_modules\.bin
5858 verbose stack     at gentlyRm (C:\Program Files\nodejs\node_modules\npm\lib\utils\gently-rm.js:49:15)
5858 verbose stack     at gentlyRmBinRoot (C:\Program Files\nodejs\node_modules\npm\lib\unbuild.js:86:12)
5858 verbose stack     at cb (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\async-map.js:47:24)
5858 verbose stack     at LOOP (C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:7:26)
5858 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:18:7
5858 verbose stack     at C:\Program Files\nodejs\node_modules\npm\lib\utils\gently-rm.js:70:40
5858 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\slide\lib\chain.js:16:22
5858 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\iferr\index.js:11:16
5858 verbose stack     at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\polyfills.js:284:29
5858 verbose stack     at FSReqWrap.oncomplete (fs.js:153:21)
5859 verbose cwd C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64\MyApplication-win32-x64\resources\app
5860 verbose Windows_NT 6.1.7601
5861 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "prune" "--production"
5862 verbose node v8.5.0
5863 verbose npm  v5.3.0
5864 error May not delete: C:\Users\MyUser\AppData\Local\Temp\electron-packager\win32-x64\MyApplication-win32-x64\resources\app\node_modules\.bin
5865 verbose exit [ 1, true ]

What command line arguments are you passing? Alternatively, if you are using the API, what parameters are you passing to the packager() function?

I am using the latest electron-packager (9.1.0) machine is using node 8.5.0 ( using its default included npm 5.3.0) I am trying to build an electron package on electron 1.7.7 (the variable referred to in the below as electronVersion)

Here is the electron-packager API call code in my gulpfile.js

var packager = require('electron-packager');

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
    overwrite: true,
    prune: true,
    electronVersion: electronVersion,    // Tell the packager what version of electron to build with
    appCopyright: pkg.copyright,         // copyright info
    appVersion: usableBuildVersion,      // 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'
    }
};

gulp.task('build:electron', function (cb) {

    $.util.log('Launching task to build & package binaries for',
        $.util.colors.cyan(opts.name),
        $.util.colors.magenta('v' + opts.appVersion)
    );
    opts.arch = process.arch;
    packager(opts, function (err, appPath) {
        if (!err) {
			// happy path
            $.util.log(' <- packagerDone()', err, appPath);
        } else {
            cb(err);
        }
    });
});

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using electron-quick-start is a good starting point.

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Comments: 34 (14 by maintainers)

Commits related to this issue

Most upvoted comments

@corvinrok

Here is the line from the package.json dependencies in 10.1.2:

https://github.com/electron-userland/electron-packager/blob/a39231997303bc0e253e26d8827710e9662dfb35/package.json#L20

The ^ means that it will install the latest 0.14.x version of asar, and as of this comment, that is 0.14.1. So, run npm update (or whatever the equivalent is on yarn, if you use yarn) and it will update the asar dependency accordingly.

@corvinrok You can try our temporary fork, which uses a forked asar, to see if it fixes the issue for you: https://www.npmjs.com/package/@ryverapp/electron-packager.

I’ve pinged one of the maintainers, but that’s not guaranteed to have a response in the time frame you might desire, as they are very busy.

I have a potential fix for this here: https://github.com/electron/asar/pull/140.

We’ve used this in our environment, with a temporarily forked electron-packager and asar, and it does seem to do the trick, both with our own app, as well as the electron-quick-start reproduction above.