0

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
Jordi Flores
  • 2,080
  • 10
  • 16
  • Perhaps you are encountering issue no. [74](https://github.com/electron/asar/issues/74) regarding _multibyte characters_ found in earlier versions. Try updating [asar](https://github.com/electron/asar) to a newer version. The issue was fixed in version [0.12.3](https://github.com/electron/asar/blob/master/CHANGELOG.md#0123---2016-08-29). Alternatively, If updating is not feasible, then check for any _multibyte characters_ in filenames/content and change them before the initial packing. – RobC Feb 16 '17 at 09:13
  • I'll try to update some packages, i'm using v0.13 on asar, but I'll give it a look. – Jordi Flores Feb 16 '17 at 09:41
  • still don't work. I'm going to update question with packages versions. – Jordi Flores Feb 16 '17 at 09:46
  • 1
    Then it's not a _multibyte character_ issue if you're running v0.13. Try installing `asar` as a project dependency. I.e. `cd` to to project directory, run `npm i -D asar` to add it to `devDependencies` in `package.json`. Then update your npm-script to `"create-asar": "node_modules/.bin/asar pack app app.asar"`. (Note `asar` is being run via the _node_modules_ _.bin_ folder). Then run `$ npm run create-asar` and see if it unpacks successfully. – RobC Feb 16 '17 at 09:58
  • @RobC with your instructions works! So it should be something related to another package, I'll try to figure what exactly it is, but feel free to post this as an answer, I'll mark it as correct as it's working like a charm. – Jordi Flores Feb 16 '17 at 14:17
  • Thanks for confirming! Yes, it certainly seems like an issue related to another globally installed package, the `asar` package itself, or possibly a dependency conflict. – RobC Feb 16 '17 at 14:51

1 Answers1

1

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.

RobC
  • 22,977
  • 20
  • 73
  • 80