Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update installation fails on macOS because of EACCES #7918

Closed
raphaelmenges opened this issue Dec 4, 2023 · 4 comments
Closed

Update installation fails on macOS because of EACCES #7918

raphaelmenges opened this issue Dec 4, 2023 · 4 comments

Comments

@raphaelmenges
Copy link

  • Electron-Builder Version: 24.9.1
  • Electron-Updater Version: 6.1.7
  • Node Version: 18.18.2
  • Electron Version: 27.1.3
  • Electron Type (current, beta, nightly): current
  • Target: macOS (arm64)

Hello developers 👋

I am trying to deploy our application for macOS. After quite some debugging, I managed to sign, notarize and setup the app and the updater. Everything works but the final step in installing the downloaded update. The log is as follows:

[2023-12-04 16:55:25.545] [info]  Install on explicit quitAndInstall
[2023-12-04 16:55:25.547] [info]  Install: isSilent: false, isForceRunAfter: false
[2023-12-04 16:55:25.548] [info]  Executing: /Users/<user-name>/Library/Caches/app-updater/pending/App-1.0.1-arm64-mac.zip with args: --updated
[2023-12-04 16:55:25.549] [info]  Cannot run installer: error code: EACCES, error message: "spawn /Users/<user-name>/Library/Caches/app-updater/pending/App-1.0.1-arm64-mac.zip EACCES", will be executed again using elevate if EACCES, and will try to use electron.shell.openItem if ENOENT
[2023-12-04 16:55:25.549] [info]  Executing: /Applications/App.app/Contents/Resources/elevate.exe with args: /Users/<user-name>/Library/Caches/app-updater/pending/App-1.0.1-arm64-mac.zip,--updated
[2023-12-04 16:55:25.550] [error] Error: Error: spawn /Applications/App.app/Contents/Resources/elevate.exe ENOENT
    at Process.onexit (node:internal/child_process:283:19)
    at onErrorNT (node:internal/child_process:476:16)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

I am highly confused why the updater attempts to run elevate.exe on a Mac!

Following some suggestions from an ancient issue, I have implemented the update installation process as follows:

setImmediate(() => {
  app.removeAllListeners("window-all-closed");
  for(const window of BrowserWindow.getAllWindows()) {
    window.close();
    window.destroy();
  }
  setTimeout(() => updater.quitAndInstall(false), 1000);
});

I have tested many different variations of this approach, e.g., with and without timeout. Updates on Windows work fine! Any hint or ideas?

@mmaietta
Copy link
Collaborator

mmaietta commented Dec 6, 2023

That's super bizarre! The only way that could happen is if it were in the NSISUpdater.ts

this._logger.info(
`Cannot run installer: error code: ${errorCode}, error message: "${e.message}", will be executed again using elevate if EACCES, and will try to use electron.shell.openItem if ENOENT`
)
if (errorCode === "UNKNOWN" || errorCode === "EACCES") {
callUsingElevation()

How are you fetching the autoUpdater?

@raphaelmenges
Copy link
Author

Hello @mmaietta!

Can you elaborate what you mean by "fetching"?

To check about NSIS influence, I have even set its configuration to false. The error persists. Here is a simplified variant of my electron-builder configuration:

return {
    productName: `app`,
    appId: `com.company.app`,
    publish: [{
      provider: "generic",
      url: "",
      channel: "latest",
    }],
    forceCodeSigning: true,
    directories: {
      output: "dist",
      buildResources: "resources",
    },
    files: ["packages/**/dist/**"],
    electronUpdaterCompatibility: ">= 2.16",
    mac: {
      category: "public.app-category.utilities",
      target: {
        target: "default",
        arch: process.env.ARCH !== undefined ? process.env.ARCH : "x64",
      },
      hardenedRuntime : true,
      gatekeeperAssess: false,
      entitlements: "resources/entitlements.mac.plist",
      entitlementsInherit: "resources/entitlements.mac.plist",
      notarize: {
        teamId: process.env.APPLE_TEAM_ID !== undefined ? process.env.APPLE_TEAM_ID : "",
      }
    },
    win: false,
    nsis: false,
    asar: true,
  };

@raphaelmenges
Copy link
Author

I now believe that I understood your comment and found out that the updater object I had created was indeed a NsisUpdater for both, Windows and macOS. After using the MacUpdater on macOS, the auto update finally worked! Including auto-start of the app after update. 🎉

I could even remove the workarounds from the ancient issue.

Thank you very much!

@mmaietta
Copy link
Collaborator

mmaietta commented Dec 8, 2023

Related note, if you use this, electron-updater will automatically provide the correct updater instance for you per-OS

import { autoUpdater } from 'electron-updater'

Object.defineProperty(exports, "autoUpdater", {
enumerable: true,
get: () => {
return _autoUpdater || doLoadAutoUpdater()
},
})

if (process.platform === "win32") {
_autoUpdater = new (require("./NsisUpdater").NsisUpdater)()
} else if (process.platform === "darwin") {
_autoUpdater = new (require("./MacUpdater").MacUpdater)()
} else {
_autoUpdater = new (require("./AppImageUpdater").AppImageUpdater)()

huhuanming added a commit to OneKeyHQ/app-monorepo that referenced this issue Apr 20, 2024
huhuanming added a commit to OneKeyHQ/app-monorepo that referenced this issue Apr 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants