Search code examples
node.jsbatch-filenpmelectronasar

Different behaviour between 'npm run' command and windows console


Here's a weird problem I'm suffering for days.

I need to create an asar packed file, done with electron "asar" command, like this:

c:/asar pack app app.asar

That packs my "app" folder into a packed file "app.asar". Thats running OK.

The goal

I need to include this instruction inside my package.json script file in order to generate a build process, chainning other actions.

The problem:

Well, when I run this command, by package.json script like this c:/npm run create-asar or either with a gulp-asar process, it creates the app.asar file, but seems to be corrupted.

It can't be unpacked, process throws an error and can't be accessed by the electron app

enter image description here

I can't figure out why.

I've tried to run the exact same command from console, that in package.json, exactly the same, and both with the results above.

what's the difference?

versions info

  • npm: v3.10.6
  • node: v4.5.0
  • asar: v0.13.0
  • electron: v1.4.3

Solution

  • Install asar locally as a project dependency, cd to your project directory and run:

    $ npm install asar --save-dev

    Change your npm-script to the following:

    "scripts": {
      "create-asar": "node_modules/.bin/asar pack app app.asar"
    },
    

    Note: asar is being executed via the local node_modules/.bin folder.

    Then run $ npm run create-asar and subsequently check whether it unpacks successfully.