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.46k stars 1.71k forks source link

Notarize notarytool JSON parsing error #8258

Open Drecula opened 3 weeks ago

Drecula commented 3 weeks ago

I am trying to notarize my app. In electron-builder.env, I have APPLE_API_KEY="my apple id" APPLE_API_KEY_ID="my apple api key" APPLE_API_ISSUER="my apple api issuer"

I do not have 'notarize' in my electron-builder.yml. My understanding is if I have these env vars, electron-builder will automatically notarize.

I have started walking back versions until I find one where this works. I will update this thread when I confirm the bugless version.

I get the below error. Please help. Thanks!

• signing file=dist/mac-arm64/MyApp.app platform=darwin type=distribution identity=9067B593388510D403BB17F8DC30B39D5077AD50 provisioningProfile=none ⨯ Unexpected token 'E', "Error: The"... is not valid JSON failedTask=build stackTrace=SyntaxError: Unexpected token 'E', "Error: The"... is not valid JSON SyntaxError: Unexpected token 'E', "Error: The"... is not valid JSON at JSON.parse (<anonymous>) at /Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/node_modules/@electron/notarize/src/notarytool.ts:79:25 at Generator.next (<anonymous>) at fulfilled (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/node_modules/@electron/notarize/lib/notarytool.js:28:58) at processTicksAnspufijections (node:internal/process/task_queues:95:5) From previous event: at processImmediate (node:internal/timers:478:21) From previous event: at readDirectoryAndSign (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/macPackager.ts:478:29) at MacPackager.signApp (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/macPackager.ts:488:11) at MacPackager.doSignAfterPack (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/platformPackager.ts:336:21) at MacPackager.doPack (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/platformPackager.ts:321:7) at MacPackager.pack (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/macPackager.ts:198:9) at Packager.doBuild (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/packager.ts:445:9) at executeFinally (/Users/spufi/gitRepos/my-app/node_modules/builder-util/src/promise.ts:12:14) at Packager._build (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/packager.ts:379:31) at Packager.build (/Users/spufi/gitRepos/my-app/node_modules/app-builder-lib/src/packager.ts:340:12) at executeFinally (/Users/spufi/gitRepos/my-app/node_modules/builder-util/src/promise.ts:12:14)

Drecula commented 2 weeks ago

Others have commented on this as well. This uses electron/notarize, which expects the notarize keys as camelCase. Perhaps the expected camelCase values could be a notarize config option instead of or in addition to the 'fully automatic' mode where electron-builder detects the notarize k/v pairs from env? The explicit options would be more self-documenting "no magic in the config" and harder to break.

Nantris commented 2 weeks ago

Same issue. Quite a strange and difficult to diagnose one. I'm not sure where I should even start looking, but it does seem related to notarization.

matjazskulj commented 6 days ago

Hey!

Did anyone perhaps solve this issue?

We're having same problems running node v20.40, electron-builder v24.13.3 and Mac M1.

We've ran notarization on the same source code as we did on 11th June and it worked back than but today it failed with the error posted on the initial post.

matjazskulj commented 6 days ago

Just fyi... I've started downgrading electron builder and on version 24.9.1 you get a whole HTTP error message. With whole HTTP error message is much easier to resolve the issue :) In our case we had to confirm new agreement on apple side.

Nantris commented 6 days ago

Thanks for sharing. When I downgrade though, it works fine, so no clues there unfortunately.

stoefln commented 2 days ago

@Nantris, which version is the one that still works? Want to downgrade too. Need this fixed ASAP

stoefln commented 1 day ago

Found a solution for myself:

After downgrading to v24.9.1, I got this information:

• selecting signing options  file=dist/mac/myapp.app/Contents/Resources/icon.icns entitlements=build/entitlements.mac.plist hardenedRuntime=true timestamp=undefined requirements=undefined
  • selecting signing options  file=dist/mac/myapp.app entitlements=build/entitlements.mac.plist hardenedRuntime=true timestamp=undefined requirements=undefined
  • executing       file=security args=delete-keychain /var/folders/s...f0be6.keychain
  • executed        file=security
  ⨯ Failed to notarize via notarytool

Error: HTTP status code: 403. A required agreement is missing or has expired. This request requires an in-effect agreement that has not been signed or has expired. Ensure your team has signed the necessary legal agreements and that they are not expired.
  failedTask=build stackTrace=Error: Failed to notarize via notarytool
                                                                                                                                                                                                                                                                                                         Error: HTTP status code: 403. A required agreement is missing or has expired. This request requires an in-effect agreement that has not been signed or has expired. Ensure your team has signed the necessary legal agreements and that they are not expired.

So I logged in to https://developer.apple.com/, saw that a license agreement needed to be accepted, did that, and things worked again.

Nantris commented 1 day ago

Unfortunately that's not the root issue here since the old version produces no error for us.

Nantris commented 1 day ago

Thank you but I just explained for the second time in this thread, that that is not our issue.

pimterry commented 10 hours ago

I also faced this issue - with no license agreements appearing when logging into https://developer.apple.com/.

Downgrading from 24.13.3 to 24.9.1 seemed to fix it for me too. I think because of https://github.com/electron-userland/electron-builder/commit/65817e0edc43a2e6707fab835b0bbe680bd0b1e4 (included in 24.9.2).

In fact, in my case the underlying issue was that due to other changes (updating MacOS version in CI, but not updating an if that set env vars for Mac only and depended on that) I was accidentally no longer setting APPLE_API_KEY in my build, and this error was an authentication failure (which presumably only appears here as 24.9.2 changes support for API keys somehow).

If you run into this and you're using API key auth, it's worth double-checking that your authentication is all set up correctly :smile:. On 24.13.3 at least, this Unexpected token 'E', "Error: The"... is not valid JSON is exactly what you'll see if it's not (it would be great if that full error was provided!)

p3x-robot commented 10 hours ago

this is weird, i am on v31 and it works.