electron-userland / electron-builder

A complete solution to package and build a ready for distribution Electron app with “auto update” support out of the box
https://www.electron.build
MIT License
13.62k stars 1.74k forks source link

asarUnpack causes strange error #7264

Closed maphstr closed 1 year ago

maphstr commented 1 year ago

Hi, i am trying to get asarUnpack to unpack a folder with scripts for me (bat, ps) that i need to be unpacked in order to run them on a windows client.

Ive located these in a folder 'scripts' and have tried every version of specifing this folder in asarUnpack i can think of. I am using angular and a 'two-package.json-structure' from this boilerplate. https://github.com/maximegris/angular-electron

electron-builder.json:

{
  "asar": true,
  "directories": {
    "output": "release/"
  },
  "files": [
    "**/*",
    "!**/*.ts",
    "!*.map",
    "!package.json",
    "!package-lock.json",
    {
      "from": "../dist",
      "filter": ["**/*"]
    }
  ],
  "asarUnpack": [
    "./scripts"
  ],
}

However, no matter how i specify "scripts" under asarUnpack, i get this error:

{"platform":"linux","arch":"x64","version":"19.0.8"}] --output /project-dir/git/angular-electron/release/linux-unpacked --distMacOsAppName Electron.app
  • map async       taskCount=2
  • map async       taskCount=1
  • map async       taskCount=74
  • exited          command=app-builder code=0 pid=1203076
  • async task error  error=/project-dir/git/angular-electron/dist/150.e37d8e7f4efc2bc5.js must be under /project-dir/git/angular-electron/app/
  ⨯ /project-dir/git/angular-electron/dist/150.e37d8e7f4efc2bc5.js must be under /project-dir/git/angular-electron/app/  failedTask=build stackTrace=Error: /project-dir/git/angular-electron/dist/150.e37d8e7f4efc2bc5.js must be under /project-dir/git/angular-electron/app/
    at getRelativePath (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/util/filter.ts:32:13)
    at AsarPackager.unpackPattern (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/util/filter.ts:57:22)
    at AsarPackager.createPackageFromFiles (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/asar/asarUtil.ts:117:82)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)
    at AsarPackager.pack (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/asar/asarUtil.ts:37:41)
    at /project-dir/git/angular-electron/node_modules/app-builder-lib/src/platformPackager.ts:418:11
    at async Promise.all (index 0)
    at AsyncTaskManager.awaitTasks (/project-dir/git/angular-electron/node_modules/builder-util/src/asyncTaskManager.ts:65:25)
    at LinuxPackager.doPack (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/platformPackager.ts:276:5)
    at LinuxPackager.pack (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/platformPackager.ts:136:5)
    at Packager.doBuild (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/packager.ts:441:9)
    at Object.executeFinally (/project-dir/git/angular-electron/node_modules/builder-util/src/promise.ts:12:14)
    at Packager._build (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/packager.ts:376:31)
    at Packager.build (/project-dir/git/angular-electron/node_modules/app-builder-lib/src/packager.ts:337:12)
    at Object.executeFinally (/project-dir/git/angular-electron/node_modules/builder-util/src/promise.ts:12:14)

Ive tried

["/"], ["scripts/"], ["/scripts/*"], ["**/scripts"]
and every variation. Always the same error.

Btw, "150.e37d8e7f4efc2bc5.js" which the error mentions is one of the built js files that are in dist, and are in the asar-archive during successfull builds (when i remove the asarUnpack line)

Anyone have any clue what is going wrong here?

Mads

DustinPham commented 1 year ago

I'm having something very similar with

/project-dir/git/angular-electron/dist/150.e37d8e7f4efc2bc5.js must be under /project-dir/git/angular-electron/app/

as well but it is for a different file. It does seem to be only with asarUnpack as well.

My config is something like:

{
  "asar": true,
  "asarUnpack": ["filename.exe"],
  "files": [
    {
      "from": "../../filename.exe"
    }
  ]
}
maphstr commented 1 year ago

I hacked this to work by tracing the error down to this line https://github.com/electron-userland/electron-builder/blob/28cb86bdcb6dd0b10e75a69ccd34ece6cca1d204/packages/app-builder-lib/src/asar/asarUtil.ts#L116

I think it might have to do with me having a two package.json structure or something, cause i saw that it tried to run this isUnpacked line on all my files in dist as well, and could not locate them.

Quick fix that seemed to work for me was to change that line with

if (file.includes('dist')) {

            isUnpacked = false;
        } else {
            isUnpacked = dirNode.unpacked || (this.unpackPattern != null && this.unpackPattern(file, stat));
        }

Not a good solution but perhaps it helps someone else.

mmaietta commented 1 year ago

That is bizarre behavior indeed. I see that both of your configs are relative and up the file tree. What happens if you add a to: "./" to the from/filter object to force a FileSet?

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

github-actions[bot] commented 1 year ago

This issue was closed because it has been stalled for 5 days with no activity.

weiyuanbj commented 1 year ago

Same issue, when i set up asarUnpack value, and electron builder will check if all files are under the root dir of my project even if i move files into it in files option. But when not set up it, electron builder will not check that. Maybe there is a issue of execution sequence of files and asarUnpack options

Devine-Davies commented 8 months ago

Hello, i seem to have gone down the same road, did any find a resolution to this ?

Version node: v18.17.1 electron: 27.3.0 electron-builder: 24.9.1

electron-builder.json

  "asarUnpack": ["**/node_modules/x/**/*",],
  "files": [
    "**/*",
    "!**/*.ts",
    "!*.map",
    {
      "from": "./../dist",
      "filter": ["**/*"]
    }
  ],
maphstr commented 8 months ago

I hacked this to work by tracing the error down to this line

https://github.com/electron-userland/electron-builder/blob/28cb86bdcb6dd0b10e75a69ccd34ece6cca1d204/packages/app-builder-lib/src/asar/asarUtil.ts#L116

I think it might have to do with me having a two package.json structure or something, cause i saw that it tried to run this isUnpacked line on all my files in dist as well, and could not locate them.

Quick fix that seemed to work for me was to change that line with

if (file.includes('dist')) { ``` isUnpacked = false; } else { isUnpacked = dirNode.unpacked || (this.unpackPattern != null && this.unpackPattern(file, stat)); } ``` Not a good solution but perhaps it helps someone else.

Is still working for me. I included a step in npm install where i overwrite a separate copy of asarUtil over the official one.

Devine-Davies commented 8 months ago

@maphstr Cheers for the response and glad you were able to resolve the issue. I did see your comment and was intrigued, I started digging around with what you suggested but hit a dead end. Would be good to see how the npm i step is configured.

I included a step in my publishing stage to move the dist folder to the correct directory before building, using cpx. I'm guessing this is a bug with electron-builder as this was previously working when not specifying asarUnpack.

maphstr commented 8 months ago

Sure, it's been a while so I don't remember exactly but this at least is the line in my package.json. I've put the modified asarUtil.js in my src/ folder.

  "scripts": {
    "postinstall": "electron-builder install-app-deps && cp src/asarUtil.js node_modules/app-builder-lib/out/asar/asarUtil.js",
    ...