electron-builder: hdiutil unmount issue blocks dmg creation for MacOS builds

Versions in use:

  • electron-builder: 21.2.0
  • electron: 5.0.2
  • node: 12.0.0

Building for MacOS

Issue:

We recently upgraded our technical stack to allow for the notarization of our app. We are using electron-notarize and for the most part, everything works as expected. Unfortunately, when building our application for distribution we are running into a problem with MacOS where the dmg creation fails about 90% of the time (you can check the supplied logs in the issue for more information). We thought that the problem might be something with our setup and we spent a significant amount of time digging into that but to no avail.

After checking things over we decided to look into electron-builder and after setting the debug flags DEBUG=electron-builder DEBUG_DMG=true we see that there is a problem when running the hdiutil command in electron-builder. I did some research and the only references to this error are back from 2016 here: https://github.com/electron-userland/electron-builder/issues/854. Unfortunately, we have no antivirus running and none of the comments in that thread have helped.

The problem we are facing really slows us down and we often have to build 10 or more times before we get a successful build. Has anyone else faced this issue? Is there something silly I am overlooking? Any help would be really appreciated. If more logs are useful then please let me know and I can post a more detailed logging output. Thanks for the help in advance.

Relevant logs:

[20:05:03] 2020-01-21 20:04:58.562 diskimages-helper[94927:334169] *useEffectiveIDs**** euid/egid changed to 501,20 (uid/gid is 501,20)
[20:05:03] DIHLDiskImageCreate() returned 49168
[20:05:03] hdiutil: create: returning 49168
[20:05:03] hdiutil: create failed - Resource busy

[20:05:03] • exited command=hdiutil code=1 pid=94924
[20:05:03] • async task error error=hdiutil exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
[20:05:26] • building embedded block map file=dist/App.zip
[20:05:26] • spawning command=/Users/builder/buildslave/app/build/node_modules/app-builder-bin/mac/app-builder blockmap --input /Users/builder/buildslave/app/build/dist/App.zip --compression deflate
[20:05:26] • exited command=app-builder code=0 pid=95022 out={"size":71064404,"sha512":"T9qUijiL5hlbvHQDF8dY8os8yKj/uTGeVmq060HtN+/MJy7ryuAxiOjq+aTXHb17h88vh7bl+yZ8LpQFFcyLDQ=="

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 12
  • Comments: 52 (1 by maintainers)

Commits related to this issue

Most upvoted comments

I wrestled with this exact issue for several hours tonight until I came across this post on superuser.com, which led me to try disabling Spotlight indexing: https://electrictoolbox.com/disable-spotlight-indexing-mac-osx/. After running sudo mdutil -a -i off the build started working immediately. If you’re still struggling with this issue, then I’d try doing the same.

As for why Sophos could have been material to other folks’ problems, I figure that’s because Sophos must scan your disk in the same problematic way that Spotlight does. That’s just speculation, though.

EDIT: changed the mdutil command to disable indexing to all stores on all volumes.

Same issue for me:

  • macOS 11.2.2 Big Sur (Macbook Air M1)
  • electron: 12.0.0
  • electron-builder: 22.10.5
  • node: 15.10.0

If a run a single arch it works: electron-builder build --mac --arm64 --publish onTagOrDraft

However it fails when using 2 arch: electron-builder build --mac --x64 --arm64 --publish onTagOrDraft

Build at: 2021-03-04T01:23:43.863Z - Hash: ed2d739a6f07b4f883f0 - Time: 45909ms
  • electron-builder  version=22.10.5 os=20.3.0
  • loaded configuration  file=package.json ("build" field)
  • writing effective config  file=package/builder-effective-config.yaml
  • packaging       platform=darwin arch=x64 electron=12.0.0 appOutDir=package/mac
  • Unpacking electron zip  zipPath=undefined
  • skipped macOS application code signing  reason=cannot find valid "Developer ID Application" identity or custom non-Apple code signing certificate, see https://electron.build/code-signing allIdentities=
                                                1) BF7784AF2A047808D55F02081F02D47922CC8219 "Thomas Champagne" (CSSMERR_TP_NOT_TRUSTED)
                                                   1 identities found
                                              
                                                Valid identities only
                                                   0 valid identities found
  • building        target=DMG arch=x64 file=package/elevate-installer.dmg
  • packaging       platform=darwin arch=arm64 electron=12.0.0 appOutDir=package/mac-arm64
  • Unpacking electron zip  zipPath=undefined
  • skipped macOS application code signing  reason=cannot find valid "Developer ID Application" identity or custom non-Apple code signing certificate, see https://electron.build/code-signing allIdentities=
                                                1) BF7784AF2A047808D55F02081F02D47922CC8219 "Thomas Champagne" (CSSMERR_TP_NOT_TRUSTED)
                                                   1 identities found
                                              
                                                Valid identities only
                                                   0 valid identities found
  • building        target=DMG arch=arm64 file=package/elevate-installer.dmg
  ⨯ Cannot cleanup: 

Error #1 --------------------------------------------------------------------------------
Error: hdiutil exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
    at ChildProcess.<anonymous> (/Users/thomas/Documents/Projects/elevate/desktop/node_modules/builder-util/src/util.ts:243:14)
    at Object.onceWrapper (node:events:485:26)
    at ChildProcess.emit (node:events:378:20)
    at maybeClose (node:internal/child_process:1067:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)

Error #2 --------------------------------------------------------------------------------
Error: hdiutil exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
    at ChildProcess.<anonymous> (/Users/thomas/Documents/Projects/elevate/desktop/node_modules/builder-util/src/util.ts:243:14)
    at Object.onceWrapper (node:events:485:26)
    at ChildProcess.emit (node:events:378:20)
    at maybeClose (node:internal/child_process:1067:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:301:5)  stackTrace=

I believe the underlying issue here is fixed by this pull request: https://github.com/LinusU/node-appdmg/pull/190

@thomaschampagne it looks like you’re creating 2 DMGs with the same name.

  • building        target=DMG arch=x64 file=package/elevate-installer.dmg
  • building        target=DMG arch=arm64 file=package/elevate-installer.dmg

Can you check your artifact or dmg title name? You may need to include an ${arch} template if you aren’t going to be using --universal builds in favor of separate x64 / arm64 builds.

Quite note: I’m unable to repro locally with electron-quick-start repo. Excerpt:

➜ /electron-quick-start/node_modules/.bin/electron-builder build --mac --x64 --arm64 -c.mac.identity=null -c.mac.target=dmg
  • electron-builder  version=22.10.5 os=20.3.0

  • writing effective config  file=dist/builder-effective-config.yaml
  • packaging       platform=darwin arch=x64 electron=11.3.0 appOutDir=dist/mac
  • building        target=DMG arch=x64 file=dist/electron-quick-start-1.0.0.dmg
  
  • packaging       platform=darwin arch=arm64 electron=11.3.0 appOutDir=dist/mac-arm64
  • building        target=DMG arch=arm64 file=dist/electron-quick-start-1.0.0-arm64.dmg

  Done in 25.58s.

Has anyone solved this? Having the same issue here Seems to be working fine on my machine but fails 95% of the time on CI

 Error: hdiutil exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE
      at ChildProcess.<anonymous> (<PATH_TO_APP>/node_modules/builder-util/src/util.ts:239:14)
      at Object.onceWrapper (events.js:428:26)
      at ChildProcess.emit (events.js:321:20)
      at maybeClose (internal/child_process.js:1026:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

OR

 Error: Exit code: 16. Command failed: hdiutil detach -force /dev/disk2
      hdiutil: couldn't eject "disk2" - Resource busy
      hdiutil: couldn't eject "disk2" - Resource busy
      at <PATH_TO_APP>/node_modules/builder-util/src/util.ts:125:16
      at ChildProcess.exithandler (child_process.js:310:5)
      at ChildProcess.emit (events.js:321:20)
      at maybeClose (internal/child_process.js:1026:16)
      at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)

Build successful as anticipated.

App · [SUCCESS] electron-builder built the app

The logger warning sounds reasonable. I’m not really qualified (experienced enough) to elaborate further. Perhaps a note in the docs would be prudent as well.

The resulting DMG opened on my Intel Mac as expected too.

Just a quick response (wasn’t able to get the debug logs yet)

arch: ‘arm64’ -> failed

building        target=DMG arch=arm64 file=dist/electron/Packaged/redacted-arm64.dmg
  • Above command failed, retrying 5 more times
  • Above command failed, retrying 4 more times
  • Above command failed, retrying 3 more times
  • Above command failed, retrying 2 more times
  • Above command failed, retrying 1 more times
  • Above command failed, retrying 0 more times

arch: ‘x64’ -> failed

  • building        target=DMG arch=x64 file=dist/electron/Packaged/redacted.dmg
  • Above command failed, retrying 5 more times
  • Above command failed, retrying 4 more times
  • Above command failed, retrying 3 more times
  • Above command failed, retrying 2 more times
  • Above command failed, retrying 1 more times
  • Above command failed, retrying 0 more times

same error: Error: hdiutil exited with code ERR_ELECTRON_BUILDER_CANNOT_EXECUTE

Will work on getting debug logs.

Also, I’m running with Sophos too, maybe that’s a hint, referring @michaelkozakovsc comment.

I recently removed Sophos AV and it was working again perfectly. Sophos was not active but still installed on the system. So I think Sophos was the issue for me.

I fixed the problem by moving all the build to Azure Pipelines.

I find solution. I remove dmg title option, and it done!!!

//dmg:{ //title: test //}

and another solution is that i write another dmg-title name… (ex) test1 or tes ) yes it is very strange issue.

I’ll be getting an M1 device in the next month or so, so I’ll be looking forward to this issue it seems haha

I am seeing this issue consistently when I try to export a dmg. I do have Sophos and cannot be disabled unfortunately. Is there any other work around?

I experienced the same thing but it appeared to happen on electron@7.1.10 with electron-builder@22.3.2 as well.

After having researched I found https://github.com/electron-userland/electron-builder/issues/2115#issuecomment-336236724 which then let me re-check the versions.

tl:dr:

  • I upgraded to the newest version (since before I had the same as you)
  • Most importantly: I deleted my global installations of electron and electron-builder. For whatever reason npx took the global ones instead of the local ones.

First make sure there is no global installation left by doing:

npm remove electron -g npm remove electron-builder -g

After that check if there is still a global one as a leftover (like in my case that was the issue):

which electron which electron-builder

After that and after upgrading the versions it should be alright.