google-api-nodejs-client icon indicating copy to clipboard operation
google-api-nodejs-client copied to clipboard

google.webmasters auth typing error with GoogleAuth<JSONClient> after v150.0.1

Open Towerss opened this issue 5 months ago • 6 comments
trafficstars

Please make sure you have searched for information in the following guides.

  • [x] Search the issues already opened: https://github.com/GoogleCloudPlatform/google-cloud-node/issues
  • [x] Search StackOverflow: http://stackoverflow.com/questions/tagged/google-cloud-platform+node.js
  • [x] Check our Troubleshooting guide: https://github.com/googleapis/google-cloud-node/blob/main/docs/troubleshooting.md
  • [x] Check our FAQ: https://github.com/googleapis/google-cloud-node/blob/main/docs/faq.md
  • [x] Check our libraries HOW-TO: https://github.com/googleapis/gax-nodejs/blob/main/client-libraries.md
  • [x] Check out our authentication guide: https://github.com/googleapis/google-auth-library-nodejs
  • [x] Check out handwritten samples for many of our APIs: https://github.com/GoogleCloudPlatform/nodejs-docs-samples

A screenshot that you have tested with "Try this API".

Hi maintainers 👋

After upgrading googleapis from version ^149.0.0 to 150.0.1, I ran into a TypeScript type error related to the auth property when initialising the webmasters API.

Image

Link to the code that reproduces this issue. A link to a public Github Repository or gist with a minimal reproduction.

https://gist.github.com/Towerss/c4885527a8ddc5e66c4cffa543398d19

A step-by-step description of how to reproduce the issue, based on the linked reproduction.

Run tsc to see the typing error.

A clear and concise description of what the bug is, and what you expected to happen.

After upgrading from googleapis@^149.0.0 to 150.0.1, TypeScript no longer accepts a GoogleAuth<JSONClient> instance as a valid auth parameter when initializing the webmasters API client.

This code worked previously:

const auth = new GoogleAuth<JSONClient>({
  keyFile: 'path/to/key.json',
  scopes: ['https://www.googleapis.com/auth/webmasters'],
});

const searchConsole = google.webmasters({ version: 'v3', auth }); // ✅ worked in v149.x

But now produces a type error in v150.0.1:

Type 'GoogleAuth<JSONClient>' is not assignable to type 'GoogleAuth<AuthClient>' Property '#private' in type 'GoogleAuth' refers to a different member that cannot be accessed from within type 'GoogleAuth'

A clear and concise description WHY you expect this behavior, i.e., was it a recent change, there is documentation that points to this behavior, etc. **

googleapis.webmasters should allow passing GoogleAuth<JSONClient> as the auth parameter, as it was supported in earlier versions and is the type returned from the current google-auth-library.

Towerss avatar Jun 06 '25 02:06 Towerss

There seems to be 2 type definitions for OAuth2Client. One was introduced from "googleapis-common": "8.0.2-rc.0"

If you import the types from googleapis-common, it fixes the type errors for me. It still conflicts with other google packages, so its not an all round fix.

Kuroson avatar Jun 06 '25 11:06 Kuroson

@Kuroson Thanks for sharing. We could also replicate the expected type locally, which is what we did while we wait for the fix. We do not use googleapis-common in the project, and the team thinks that adding it just to extract the type to keep webmasters happy does not justify adding a new package.

Hopefully, the maintainers will help us with this one soon :) @

Towerss avatar Jun 08 '25 04:06 Towerss

can you confirm what npm ls google-auth-library is in your project? This may be due to mismatched versions of auth (~9 !== 10)

sofisl avatar Jun 10 '25 20:06 sofisl

Hi @sofisl , Thanks for looking into this.

This is the output of the command npm ls google-auth-library:

[email protected] C:\Users\x\Desktop\Projects\api
├─┬ @google-cloud/[email protected] -> .\node_modules\.pnpm\@[email protected]\node_modules\@google-cloud\recaptcha-enterprise
│ └─┬ [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\google-gax
│   └── [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library
├─┬ @google-cloud/[email protected] -> .\node_modules\.pnpm\@[email protected]\node_modules\@google-cloud\translate
│ ├─┬ @google-cloud/[email protected] -> .\node_modules\.pnpm\@[email protected]\node_modules\@google-cloud\common
│ │ └── [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library
│ ├── [email protected] deduped invalid: "^10.0.0-rc.1" from node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/translate -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library
│ └─┬ [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\google-gax
│   └── [email protected] deduped -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library
├── [email protected] invalid: "^10.0.0-rc.1" from node_modules/.pnpm/@[email protected]/node_modules/@google-cloud/translate -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library
└─┬ [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\googleapis    
  ├── [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library
  └─┬ [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\googleapis-common
    └── [email protected] -> .\node_modules\.pnpm\[email protected]\node_modules\google-auth-library

npm error code ELSPROBLEMS
npm error invalid: [email protected] C:\Users\x\Desktop\Projects\api\node_modules\google-auth-library
npm error A complete log of this run can be found in: C:\Users\x\AppData\Local\npm-cache\_logs\2025-06-11T00_03_12_376Z-debug-0.log

Towerss avatar Jun 11 '25 00:06 Towerss

It seems like this might be the issue. I am attempting to publish 10 right now which would solve the problem, or else just make sure to install google-auth-library-nodejs@rc

sofisl avatar Jun 11 '25 00:06 sofisl

Thanks @sofisl,

After upgrading to version 10, we continue having the same typing issue. We decided to uninstall "google-auth-library": "^10.0.0", and we are trying auth from "googleapis": "^150.0.1":

const auth = new google.auth.GoogleAuth({
	keyFile: googleCredentialsPath,
	scopes: ['https://www.googleapis.com/auth/webmasters'],
});


const searchConsole = google.webmasters({ version: 'v3', auth });

So far, it seems to be working fine, but the release of "google-auth-library": "^10.0.0" did not solve the type issue for us.

Towerss avatar Jun 11 '25 05:06 Towerss

I recently updated another library (that wasn't on 10 as well). If you run rm -rf node_modules && rm -rf package-lock.json && npm i, while installing the latest (not rc) of all the libraries, can you tell me if it works?

sofisl avatar Jun 18 '25 17:06 sofisl

This has been closed since a request for information has not been answered for 15 days. It can be reopened when the requested information is provided.

github-actions[bot] avatar Jul 04 '25 02:07 github-actions[bot]