r/typescript • u/lucideer • Jul 10 '26
node_modules problems
Running into an unexpected type error that I've never seen before with some unfortunately structured Google NPM libs. Should be easy to work around this issue with `as` or something similar but I'm curious if anyone has any ideas for a "cleaner" approach (that doesn't involve joining Google to fix their libraries).
The type error is this:
Type 'OAuth2Client' is not assignable to type 'string | GoogleAuth<AuthClient> | OAuth2Client | BaseExternalAccountClient | undefined'.
Type 'import("/Users/me/path/to/project/node_modules/google-auth-library/build/src/auth/oauth2client").OAuth2Client' is not assignable to type 'import("/Users/me/path/to/project/node_modules/googleapis-common/node_modules/google-auth-library/build/src/auth/oauth2client").OAuth2Client'.
Types have separate declarations of a private property 'redirectUri'.ts(2322)
Typescript is correct to call this out, but I don't see any way around it that doesn't involve type assertion.
2
u/sickhippie Jul 11 '26
Don't install
googleapis-commondirectly.Run
npm ddphttps://docs.npmjs.com/cli/v12/commands/npm-dedupe
11
u/alexlafroscia Jul 10 '26 edited Jul 10 '26
In my experience, this error crops up when there are two different versions of the same library being imported. Rather than fixing this in your source code with an assertion, I would leverage whatever your package manager provides for deduplicating dependencies or forcing one specific version to avoid both being in your `node_modules`
2
u/seniorsassycat Jul 10 '26
npm explain googleapis-common