electron-builder: Notarize failed with 24.13.3 after upgrade from 24.12.0 with app specific password

  • Electron-Builder Version: 24.13.3
  • Node Version: 18.18.2
  • Electron Version: 28.2.5
  • Electron Type (current, beta, nightly): stable
  • Target: macos-12 dmg darwin-64

I upgraded electron builder from 24.12.0 to 24.13.3 and notarizing failed with

Cannot destructure property 'appBundleId' of 'options' as it is undefined. 

I am using APPLE_ID and APPLE_APP_SPECIFIC_PASSWORD approach for authorization. Since i did not find out what changed, i tried to force new notarytool.

I checked the code how notarize options are build. And it should be possible to set

{
  mac: {
    notarize: {
      teamId: "TEAM_ID"
    }
  }
}

even when using apple id and app specific password for authorization. the new notarytool should be used following the source code in https://github.com/electron-userland/electron-builder/blob/master/packages/app-builder-lib/src/macPackager.ts#L566. But when setting the team id i get this:

-> Options related to how build macOS targets.
   Details:
    * configuration.mac.notarize has an unknown property 'teamId'. These properties are valid:
      object { appBundleId?, ascProvider? }
    * configuration.mac.notarize has an unknown property 'tool'. These properties are valid:
      object { appBundleId?, ascProvider? }
    * configuration.mac.notarize has an unknown property 'tool'. These properties are valid:
      object { teamId }
    * configuration.mac.notarize misses the property 'teamId'. Should be:
      string
      -> The team ID you want to notarize under for when using `notarytool`

So what did i miss in the version update that notarizing is not working anymore?

Thank you!

EDIT: Downgraded to 24.12.0 again and removed the notarize key from the builder config. and it is working again.

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 6
  • Comments: 15 (4 by maintainers)

Commits related to this issue

Most upvoted comments

I hit the same issue that reported here.

Newer electron-builder has a built-in notarize option that works out of the box as @KillerCodeMonkey mentioned. On the other hand, the old way that uses the afterSign option to invoke a script to manually call electron-notarize doesn’t work well with electron-builder 24.13.3.

I removed the afterSign option in my script and added the following config to package.json and now everything works without issues. I’m still using APPLE_APP_SPECIFIC_PASSWORD, but it looks that’s just fine.

...under mac..
     "notarize": {
        "teamId": "YOUR_TEAM_ID"
      }

If you have the following env variables, it will try to notarize automatically

  1. APPLE_API_KEY, APPLE_API_KEY_ID and APPLE_API_ISSUER.
  2. APPLE_ID, APPLE_APP_SPECIFIC_PASSWORD, and APPLE_TEAM_ID
  3. APPLE_KEYCHAIN and APPLE_KEYCHAIN_PROFILE

What a guessing game.

the afterSign option to invoke a script to manually call electron-notarize doesn’t work well with electron-builder 24.13.3

How so?

I am still using this approach and it works fine. Just ensure to set build.mac.notarize to false in package.json, to avoid attempting it twice.

Here is my afterSign.js file, set in build.afterSign. Note that I load the credentials from a file using dotenv; I do not pass them via runtime environment variables:

const path = require('path');
require('dotenv').config();
require('dotenv').config({ path: path.resolve(__dirname, '..', '..', '.credentials') });
const { spawnSync } = require('child_process');
const { notarize } = require('@electron/notarize');

async function notarizeMacos(context) {
  const { appOutDir } = context;

  const {
    APPLE_ID,
    APPLE_APP_SPECIFIC_PASSWORD,
    APPLE_TEAM_ID,
  } = process.env;

  if (!(APPLE_ID && APPLE_APP_SPECIFIC_PASSWORD && APPLE_TEAM_ID)) {
    console.log('Skipping notarizing step. APPLE_ID, APPLE_APP_SPECIFIC_PASSWORD, and APPLE_TEAM_ID env variables must be set');
    return;
  }

  if (process.env.SKIP_NOTARIZE !== undefined) {
    console.warn('Skipping notarizing step. SKIP_NOTARIZE env variable is set.');
    return;
  }

  const appName = context.packager.appInfo.productFilename;

  console.log('Notarizing macOS app...');
  await notarize({
    // appBundleId: build.appId,
    appPath: `${appOutDir}/${appName}.app`,
    appleId: APPLE_ID,
    appleIdPassword: APPLE_APP_SPECIFIC_PASSWORD,
    teamId: APPLE_TEAM_ID,
  });
}

exports.default = async function notarizeOrSign(context) {
  const { electronPlatformName } = context;
  if (electronPlatformName === 'darwin') {
    await notarizeMacos(context);
  } else {
    console.log(`No notarization or signing for platform ${electronPlatformName}`);
  }
};

I also had to downgrade to get things rolling again.

It seems that in v24.13.3, notarize is being called somewhere while disregarding the script specified by afterSign.

The error I was getting: Cannot destructure property 'appBundleId' of 'options' as it is undefined. failedTask=build stackTrace=TypeError: Cannot destructure property 'appBundleId' of 'options' as it is undefined..

It seems like this “other” notarize is being called based on a trigger other than the afterSign config.