Electron-builder: Cannot get `asar-unpack` to work

Created on 11 May 2016  ยท  7Comments  ยท  Source: electron-userland/electron-builder

Our Electron app uses convert from ImageMagick, and that needs some .xml files alongside the binary. Our electron folder ends up looking like this:

public/
โ”œโ”€โ”€ external/
โ”‚ย ย  โ”œโ”€โ”€ colors.xml
โ”‚ย ย  โ”œโ”€โ”€ convert
โ”‚ย ย  โ”œโ”€โ”€ delegates.xml
โ”‚ย ย  โ””โ”€โ”€ magic.xml
โ”œโ”€โ”€ app.css
โ”œโ”€โ”€ app.js
โ”œโ”€โ”€ electron-main.js
โ”œโ”€โ”€ index.html
โ”œโ”€โ”€ package.json
โ””โ”€โ”€ vendor.js

I'm able to run asar pack public/ public.asar --unpack 'public/external/*' and get both public.asar and public.asar.unpacked, but I cannot for the life of me figure out the path to be passed via build.asar-unpack in the development package.json.

I've tried ...

  "build": {
    "asar-unpack": "public/external/*"
  }
  "build": {
    "asar-unpack": "external/*"
  }
  "build": {
    "asar-unpack": "app/external/*"
  }
  "build": {
    "asar-unpack": "*/external/*"
  }
  "build": {
    "asar-unpack": "dist/ProductName-darwin-x64/Electron.app/Contents/Resources/app/external/*"
  }

... But am not able to get app.asar.unpacked. Is there anything I'm missing?

feature

Most helpful comment

Thank you @mikew for also sharing your answer. In 2018 this worked:

"mac": {
  ...
  "target": "dmg",
  "asar": true,
  "asarUnpack": [
    "../node_modules/@ffmpeg-installer"
  ]
}

Successfully get this once the _dmg_ is installed:

contents/
โ”œโ”€โ”€ Resources/
โ”‚   โ”œโ”€โ”€ app.asar
โ”‚   โ””โ”€โ”€ app.asar.unpacked/
โ”‚       โ””โ”€โ”€ node_modules/
โ”‚           โ””โ”€โ”€ @ffmpeg-installer/

Now the tricky part is referring to it from within your app :trollface:
This hazardous workaround seems to work with basically 1 line of code: https://github.com/electron/electron/issues/6262#issuecomment-273312942

All 7 comments

Ah, figured it out. Using a globstar works, and no matter your directory structure, your files will be under app/. The following works:

  "build": {
    "asar-unpack": "**/app/external/*"
  }

It is the shame because we inherit this configuration option from the electron-packager. So, it is not smart and not user-friendly and no any checks :( So sad :( We will rework and introduce new smart option.

Fixed โ€“ now we correctly set cwdfor glob and relative patterns work. (it was bug in the asar).

Also you can use extraResources .

Please note asar-unpack is deprecated, use asar as object of options.

Thank you @mikew for also sharing your answer. In 2018 this worked:

"mac": {
  ...
  "target": "dmg",
  "asar": true,
  "asarUnpack": [
    "../node_modules/@ffmpeg-installer"
  ]
}

Successfully get this once the _dmg_ is installed:

contents/
โ”œโ”€โ”€ Resources/
โ”‚   โ”œโ”€โ”€ app.asar
โ”‚   โ””โ”€โ”€ app.asar.unpacked/
โ”‚       โ””โ”€โ”€ node_modules/
โ”‚           โ””โ”€โ”€ @ffmpeg-installer/

Now the tricky part is referring to it from within your app :trollface:
This hazardous workaround seems to work with basically 1 line of code: https://github.com/electron/electron/issues/6262#issuecomment-273312942

I have this problem:
screenshot from 2018-02-28 14-02-57

I tried this and it didn't work
js "asar": true, "asarUnpack": ["../node_modules/sqlite3"],
any idea?

@challenger532 try changing:
"asarUnpack": ["../node_modules/sqlite3"],

to

"asarUnpack": ["node_modules/sqlite3"],

Was this page helpful?
0 / 5 - 0 ratings

Related issues

talarari picture talarari  ยท  3Comments

JohnWeisz picture JohnWeisz  ยท  3Comments

omarkilani picture omarkilani  ยท  3Comments

xingoxu picture xingoxu  ยท  3Comments

noahprince22 picture noahprince22  ยท  3Comments