electron / notarize

Notarize your macOS Electron Apps
MIT License
130 stars 31 forks source link

Error: Failed to staple your application with code: 64 when notarizing on MacOS 13.0 Dev 2 #109

Closed r0hin closed 1 year ago

r0hin commented 2 years ago

I am trying to notarize the MacOS distributions of my application using the afterSign field for electron-builder, and have been receiving the following error:

Error: Failed to staple your application with code: 64

Usage: stapler staple [-q] [-v] path
        Retrieves a ticket and attaches it to the supported file
        format at path.

Usage: stapler validate [-q] [-v] path
        Validates an existing stapled ticket.

Supported file formats are: UDIF disk images, code-signed executable
bundles, and signed "flat" installer packages.

    at Object.<anonymous> (/Users/rohin/GitHub/parallel2/app/node_modules/electron-notarize/src/staple.ts:16:11)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/rohin/GitHub/parallel2/app/node_modules/electron-notarize/lib/staple.js:4:58)
    at processTicksAndRejections (node:internal/process/task_queues:95:5)

The code I am running in my notarization script is:

const value = await notarize({
    tool: "notarytool",
    appPath: "./dist/mac-arm64/{appName}.app",
    appleId: process.env.APPLE_ID,
    appleIdPassword: process.env.APPLE_ID_PASSWORD,
    teamId: process.env.APPLE_TEAM_ID,
});

The dependency versions are:

"devDependencies": {
    "electron": "^19.0.4",
    "electron-builder": "^23.0.3",
    "electron-notarize": "^1.2.1"
  },

I am running MacOS Ventura 13.0 Developer Beta 2 which could have something to do with it.

Thank you for your help!

yhtt2020 commented 2 years ago

i've got same problem

suan commented 2 years ago

Same problem here

EDIT: Tried installing the XCode beta, no difference

suan commented 2 years ago

The accepted answer here might explain it (builds made on a beta version of MacOS aren't accepted) https://developer.apple.com/forums/thread/682597

ragauskl commented 2 years ago

Stapling works just fine if you skip '-v' arg for 'xcrun stapler staple' that is used within notarize() as last step, as there's no option to skip stapling I just added a catch for quick workaround:

try {
  await electronNotarize.notarize({ ... })
} catch (error) {
  if (error.message?.includes('Failed to staple')) {
    spawn(`xcrun`, ['stapler', 'staple', appPath])
  } else {
    throw error
  }
}
suan commented 2 years ago

Thanks @ragauskl and the final build after notarization and stapling works fine on Monterey and earlier?

ragauskl commented 2 years ago

Worked for me on Monterey (built on laptop with Ventura and tested on different computer with Monterey), but haven't tested anything older than that.

My guess would be that it should not cause issues as problem is more likely on beta OS with the validation logic/recognising .app file as a valid file format for stapling, and not a problem with stapling itself

suan commented 2 years ago

Worked for me too! Here's my approach with spawnSync and status-checking and output:

    if (error.message?.includes('Failed to staple')) {
      console.log('RETRY staple as per https://github.com/electron/electron-notarize/issues/109#issuecomment-1213359106');

      const result = spawnSync('xcrun', ['stapler', 'staple', appPath]);
      console.log('STDOUT: ', result.stdout.toString());
      console.log('STDERR: ', result.stderr.toString());

      if (result.status !== 0) {
        throw new Error(
          `RETRY: Failed to staple your application with return status: ${result.status}`,
        );
      }

      console.log('RETRY: staple succeeded');
    } else {
      throw error;
    }
MarshallOfSound commented 1 year ago

Duplicate of #31

kartikkalia7 commented 1 year ago

Not working for me electron-builder 24.6.3 electron 25.0.1

error thown CloudKit query for hrms.app (2/ab4c9d44868c551e173029342b41d4b38ad024f2) failed due to "Record not found". Could not find base64 encoded ticket in response for 2/ab4c9d44868c551e173029342b41d4b38ad024f2 The staple and validate action failed! Error 65.

raghavnaphade commented 1 year ago

JSON Response is: { records = ( { reason = "Record not found"; recordName = "2/2/081ef50fe92295985a30a12db7dd0acc5d0fe377"; serverErrorCode = "NOT_FOUND"; } ); } CloudKit query for xyz.app (2/081ef50fe...) failed due to "Record not found". Could not find base64 encoded ticket in response for 2/081ef50... The staple and validate action failed! Error 65. failedTask=build stackTrace=Error: Failed to staple your application with code: 65

`require('dotenv').config(); const { notarize } = require('@electron/notarize');

exports.default = async function notarizing(context) { const { electronPlatformName, appOutDir } = context;
if (electronPlatformName !== 'darwin') { return; }

const appName = context.packager.appInfo.productFilename; return await notarize({ appBundleId: 'com.bundleId', appPath: ${appOutDir}/${appName}.app, appleId: appid, appleIdPassword: abc, teamId: 123 }); };`

I have multiple certifcates for different projects