MMM-GoogleCalendar icon indicating copy to clipboard operation
MMM-GoogleCalendar copied to clipboard

Problem Running node authorize.js

Open raspberrypi9 opened this issue 1 year ago • 11 comments

I generated an Oauth client ID in the Google interface and placed it in the file credentials.json in the MMM-GoogleCalendar directory. When I run: node authorize.js, it says:

MMM-GoogleCalendar: Error loading credentials Error: ENOENT: no such file or directory, open '/home/mjw/MagicMirror/modules/MMM-GoogleCalendar/token.json'

I tried cp credentials.json token.json but I got:

MMM-GoogleCalendar: Error loading credentials Error: The incoming JSON object does not contain a client_email field

I'm not sure what else to try now. If you would please offer some help, I would really appreciate it. Thank you.

raspberrypi9 avatar Nov 19 '24 16:11 raspberrypi9

can you edit the credentials.json

it is missing a field The incoming JSON object does not contain a client_email field

did you provide all the info, and select the right type of credentials?

sdetweil avatar Nov 19 '24 17:11 sdetweil

I did download the credentials but it doesn't have a client_email field. Should it? I tried hand editing it to add one but that didn't work I am doing OAuth client ID Also, I put the credentials file as credentials.json in the MMM-Google Calendar dir but it was looking for a token.js

raspberrypi9 avatar Nov 19 '24 20:11 raspberrypi9

We are currently using Node.js version 22.9.0 in our project, and we are encountering a deprecation warning related to the Punycode module alongside the MMM-GoogleCalendar: Error loading credentials Error: ENOENT: no such file or directory, open '~/MagicMirror/modules/MMM-GoogleCalendar/token.json'.

Could you please provide guidance on how to resolve or address this issue? Should we replace the Punycode module with an alternative, or are there any specific updates or configurations we should apply to avoid this warning?

Looking forward to your advice.

Thank you.

michaelhlee00 avatar Nov 20 '24 18:11 michaelhlee00

Here the same, these are my outputs:


node@mm:/opt/magic_mirror/modules/MMM-GoogleCalendar$ node --trace-deprecation authorize.js (node:229) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. at node:punycode:3:9 at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:399:7) at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:338:10) at loadBuiltinModule (node:internal/modules/helpers:114:7) at Function._load (node:internal/modules/cjs/loader:1100:17) at TracingChannel.traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:218:24) at Module.require (node:internal/modules/cjs/loader:1340:12) at require (node:internal/modules/helpers:141:16) at Object. (/opt/magic_mirror/modules/MMM-GoogleCalendar/node_modules/whatwg-url/lib/url-state-machine.js:2:18) MMM-GoogleCalendar: Error loading credentials Error: ENOENT: no such file or directory, open '/opt/magic_mirror/modules/MMM-GoogleCalendar/token.json' at async open (node:internal/fs/promises:638:25) at async Object.readFile (node:internal/fs/promises:1238:14) at async loadSavedCredentialsIfExist (/opt/magic_mirror/modules/MMM-GoogleCalendar/authorize.js:22:21) at async authorize (/opt/magic_mirror/modules/MMM-GoogleCalendar/authorize.js:55:16) { errno: -2, code: 'ENOENT', syscall: 'open', path: '/opt/magic_mirror/modules/MMM-GoogleCalendar/token.json' }

And after "cp credentials.json token.json":


node@mm:/opt/magic_mirror/modules/MMM-GoogleCalendar$ node --trace-deprecation authorize.js (node:346) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. at node:punycode:3:9 at BuiltinModule.compileForInternalLoader (node:internal/bootstrap/realm:399:7) at BuiltinModule.compileForPublicLoader (node:internal/bootstrap/realm:338:10) at loadBuiltinModule (node:internal/modules/helpers:114:7) at Function._load (node:internal/modules/cjs/loader:1100:17) at TracingChannel.traceSync (node:diagnostics_channel:315:14) at wrapModuleLoad (node:internal/modules/cjs/loader:218:24) at Module.require (node:internal/modules/cjs/loader:1340:12) at require (node:internal/modules/helpers:141:16) at Object. (/opt/magic_mirror/modules/MMM-GoogleCalendar/node_modules/whatwg-url/lib/url-state-machine.js:2:18) MMM-GoogleCalendar: Error loading credentials Error: The incoming JSON object does not contain a client_email field at JWT.fromJSON (/opt/magic_mirror/modules/MMM-GoogleCalendar/node_modules/google-auth-library/build/src/auth/jwtclient.js:210:19) at AuthPlus.fromJSON (/opt/magic_mirror/modules/MMM-GoogleCalendar/node_modules/google-auth-library/build/src/auth/googleauth.js:385:20) at loadSavedCredentialsIfExist (/opt/magic_mirror/modules/MMM-GoogleCalendar/authorize.js:24:24) at async authorize (/opt/magic_mirror/modules/MMM-GoogleCalendar/authorize.js:55:16)

Sebastardito avatar Dec 01 '24 07:12 Sebastardito

The no such file or directory error log is a red herring due to poor error handling.

What is likely happening is that the local-auth library is trying to open your default browser unsuccessfully which is what happened to me. As a band-aid fix, I edited node_modules/@google-cloud/local-auth/build/src/index.js and added console.log("URL: " + authorizeUrl) after this block of code:

            // open the browser to the authorize url to start the workflow
            const authorizeUrl = client.generateAuthUrl({
                redirect_uri: redirectUri.toString(),
                access_type: 'offline',
                scope: scopes.join(' '),
            });

and then you can copy the link that prints in the console next time you run it.

nmlynch94 avatar Jan 22 '25 04:01 nmlynch94

Howdy, I am running in to the same issue. I followed the instructions, but on here it says select internal and I did not have that option and selected external with all the same settings. I downloaded the credentials.json and when I run the authorize.js it errors out with what is below. This is a new install as of 2 days ago.

(node:70729) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. (Use node --trace-deprecation ... to show where the warning was created) MMM-GoogleCalendar: Error loading credentials Error: ENOENT: no such file or directory, open '/home/phil/MagicMirror/modules/MMM-GoogleCalendar/token.json' at async open (node:internal/fs/promises:639:25) at async Object.readFile (node:internal/fs/promises:1243:14) at async loadSavedCredentialsIfExist (/home/phil/MagicMirror/modules/MMM-GoogleCalendar/authorize.js:23:21) at async authorize (/home/phil/MagicMirror/modules/MMM-GoogleCalendar/authorize.js:56:16) { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/phil/MagicMirror/modules/MMM-GoogleCalendar/token.json' }

Then I have to cancel out, it just sits there.

Any help would be appreciated.

aa0pb avatar Jan 29 '25 03:01 aa0pb

The no such file or directory error log is a red herring due to poor error handling.

What is likely happening is that the local-auth library is trying to open your default browser unsuccessfully which is what happened to me. As a band-aid fix, I edited node_modules/@google-cloud/local-auth/build/src/index.js and added console.log("URL: " + authorizeUrl) after this block of code:

            // open the browser to the authorize url to start the workflow
            const authorizeUrl = client.generateAuthUrl({
                redirect_uri: redirectUri.toString(),
                access_type: 'offline',
                scope: scopes.join(' '),
            });

and then you can copy the link that prints in the console next time you run it.

This was a successful solution for me. Thank you!

pseudosystem avatar Mar 20 '25 20:03 pseudosystem

Howdy, I am running in to the same issue. I followed the instructions, but on here it says select internal and I did not have that option and selected external with all the same settings. I downloaded the credentials.json and when I run the authorize.js it errors out with what is below. This is a new install as of 2 days ago.

(node:70729) [DEP0040] DeprecationWarning: The punycode module is deprecated. Please use a userland alternative instead. (Use node --trace-deprecation ... to show where the warning was created) MMM-GoogleCalendar: Error loading credentials Error: ENOENT: no such file or directory, open '/home/phil/MagicMirror/modules/MMM-GoogleCalendar/token.json' at async open (node:internal/fs/promises:639:25) at async Object.readFile (node:internal/fs/promises:1243:14) at async loadSavedCredentialsIfExist (/home/phil/MagicMirror/modules/MMM-GoogleCalendar/authorize.js:23:21) at async authorize (/home/phil/MagicMirror/modules/MMM-GoogleCalendar/authorize.js:56:16) { errno: -2, code: 'ENOENT', syscall: 'open', path: '/home/phil/MagicMirror/modules/MMM-GoogleCalendar/token.json' }

Then I have to cancel out, it just sits there.

Any help would be appreciated.

See the solution by nmlynch94 above

pseudosystem avatar Mar 20 '25 20:03 pseudosystem

Hello,

Same problem here, but I don't have node_modules/@google-cloud to apply nmlynch94's solution. I ran npm install that says up to date, audited 383 packages in 2s

65 packages are looking for funding run npm fund for details

1 low severity vulnerability

To address all issues, run: npm audit fix

Run npm audit for details.

I have to say that I have no skill in js.

Thanks for your help

ludalito avatar Jun 17 '25 21:06 ludalito

Same situation as everyone else. I'm attempting to set this up via SSH and thus the authorize.js cannot open a browser. The documentation clearly states "The script will output a URL. Copy this URL." but no URL was ever output. Perhaps the google library has changed and the docs are now out of date?

In any case, @nmlynch94 's fix worked for me. It output the URL, I copied into browser, auth'd, then it tried to redirect me to 'http://localhost:42247/...' To finish, I opened a second SSH session and simply curl'd that URL which finally completed the entire process.

Please update the docs, or provide a fix so that the URL is output as indicated in the docs.

utdrmac avatar Sep 23 '25 03:09 utdrmac

im not the best when i comes to programming so ive done the fix but i get the following after the op error.

node authorize.js /home/pi/MagicMirror/modules/MMM-GoogleCalendar/node_modules/@google-cloud/local-auth/build/src/index.js:124 }); ^

SyntaxError: Unexpected token ')' at wrapSafe (node:internal/modules/cjs/loader:1620:18) at Module._compile (node:internal/modules/cjs/loader:1662:20) at Object..js (node:internal/modules/cjs/loader:1820:10) at Module.load (node:internal/modules/cjs/loader:1423:32) at Function._load (node:internal/modules/cjs/loader:1246:12) at TracingChannel.traceSync (node:diagnostics_channel:322:14) at wrapModuleLoad (node:internal/modules/cjs/loader:235:24) at Module.require (node:internal/modules/cjs/loader:1445:12) at require (node:internal/modules/helpers:135:16) at Object. (/home/pi/MagicMirror/modules/MMM-GoogleCalendar/authorize.js:4:26)

kash1982 avatar Oct 09 '25 13:10 kash1982