electron/notarize

Unexpected token E in JSON at position 0

akshitcompro opened this issue ยท 19 comments

We are facing the below error on using @electron/notarize v2.3.0

image

Not sure, what's the actual issue here. We are providing all the required params to the notarize function:

image

Having the same issue

This is the same issue as #177.

Same here

Looks like it is trying to parse a JSON that is not actually a JSON. notarytool returns a string instead of JSON when there is an error occurs.
I modified the node_modules/@electron/notarize/lib/notarytool.js file to make it throw an error with the JSON string, so that I can see the actual error message from Apple.

const result = yield (0, spawn_1.spawn)('xcrun', notarizeArgs);

throw new Error(result.output.trim());

const parsed = JSON.parse(result.output.trim());

For me the error is "Error: HTTP status code: 403. Invalid or inaccessible developer team ID for the provided Apple ID. Ensure the Team ID is correct and that you are a member of that team."

Turned out that you need to sign some new agreement on Apple Developer site.

rotu commented

Turned out that you need to sign some new agreement on Apple Developer site.

That may have been the case for you, but there are many other reasons the command can print non-JSON output.

Strangely, it still fails for me when using the plugin as is.

This change in node_modules/@electron/notarize/lib/notarytool.js magically fixes it for me:

            const result = yield (0, spawn_1.spawn)('xcrun', notarizeArgs);
            console.log('Attempting to parse that crap:', result.output.trim());
            let parsed;
            try {
                parsed = JSON.parse(result.output.trim());
            } catch (e) {
                console.error("Failed to parse JSON:", e);
                throw new Error(result.output.trim());
            }

Had the same issue, currently forking the repo to apply the above fix.

Good morning, i have the same problem. i run notarize on a gitaction. when i am on local i have no problem but when the operation is run on GitHub instead i get that error message. I tried to fork the library and added the fix of 'EternallLight' but it doesn't seem to be used. Any advice?

Rollback to version 2.2.0 where JSON is parsed correctly.

"@electron/notarize": "2.2.0"

Also be sure to add resolutions to your package.json so your other electron packages use the correct version.

"resolutions": {
"@electron/notarize": "2.2.0"
}

Ok, with the rollback to 2.2.0 the error has changed. now it says "Error: HTTP status code: 401. Not authenticated. Make sure all authentication arguments are correct." but when I run notarize locally everything is fine. The problem occurs only on gitactions. I use the three environment variables:

APPLE_API_KEY: ~/private_keys/AuthKey_${{ secrets.api_key_id }}.p8
APPLE_API_KEY_ID: ${{ secrets.api_key_id }}
APPLE_API_ISSUER: ${{ secrets.api_key_issuer_id }}

Turned out that you need to sign some new agreement on Apple Developer site.

Hi @andelf, can you provide more feedback as to what was missing?

I am encountering the same problem. May I ask if there is any way to solve it?

I have encountered this issue in my attempts. Leaving this here as it may help someone else.

The error for me happened when the notarize function tried to parse the response from the initial request.
In my case, it ended up being an issue with authentication as my Apple ID was wrong, so it return an error message ( Error: HTTP status code: 401. Invalid credentials... hence the start with E)

I guess electron-notarize could be more helpful in providing a better error as suggested in #191

Turned out that you need to sign some new agreement on Apple Developer site.

Thank you

I was also able to fix this by logging into my Apple Developer account and accepting the updated agreement.

rotu commented

This should be fixed by #191

Turned out that you need to sign some new agreement on Apple Developer site.

for me as well

If someone like me ended here today looking for solutions, make sure to npm update @electron/notarize and, as stated before, accept new terms on the Apple side of things.

For anyone else looking for quick link, go to https://appstoreconnect.apple.com/business and accept any agreements you have there ๐Ÿ‘