Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JWT Class import issue #1697

Closed
MorpheusZI opened this issue Nov 28, 2023 · 9 comments
Closed

JWT Class import issue #1697

MorpheusZI opened this issue Nov 28, 2023 · 9 comments
Assignees
Labels
external This issue is blocked on a bug with the actual product. priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue. web

Comments

@MorpheusZI
Copy link

MorpheusZI commented Nov 28, 2023

I was trying to authenticate a ServiceAccount using JWT by doing doing this :

//... other imports
import { GoogleSpreadSheet } from "google-spreadsheet"
import { JWT } from "google-auth-library"

// ... some other code
const ServiceAccAuth = new JWT({
          email: creds.client_email,
          key: creds.private_key,
          scopes: [
            "https://www.googleapis.com/auth/spreadsheets",
            "https://www.googleapis.com/auth/drive.file",
          ],
        });
const doc = new GoogleSpreadsheet("MY-SPREADSHEET-ID" ServiceAccAuth);

after doing that i got a console error saying "Uncaught TypeError: Class extends value undefined is not a constructor or null
at node_modules/agent-base/dist/index.js (index.ts:29:42)
at __require2 (chunk-3EJPJMEH.js?v=04702791:15:50)
at node_modules/https-proxy-agent/dist/index.js (index.ts:7:1)
at __require2 (chunk-3EJPJMEH.js?v=04702791:15:50)
at node_modules/gaxios/build/src/gaxios.js (gaxios.ts:33:1)
at __require2 (chunk-3EJPJMEH.js?v=04702791:15:50)
at node_modules/gaxios/build/src/index.js (index.ts:15:1)
at __require2 (chunk-3EJPJMEH.js?v=04702791:15:50)
at node_modules/gcp-metadata/build/src/index.js (index.ts:8:1)
at __require2 (chunk-3EJPJMEH.js?v=04702791:15:50)"

Notes: im using React,Typescript and a vite bundler
idek if its a bug or something so i put it on the "bug" type
read online somebody had this issue too said it was an import issue,didnt find any answers i could provide yall with some extra details if ya want

@MorpheusZI MorpheusZI added priority: p2 Moderately-important priority. Fix may not be included in next release. type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 28, 2023
@danielbankhead
Copy link
Contributor

Hey @MorpheusZI,

This sounds like a duplicate of this issue:

Looking at the error message in the log you posted, it looks like somehow http.Agent is undefined here:

https://github.com/TooTallNate/proxy-agents/blob/b133295fd16f6475578b6b15bd9b4e33ecb0d0b7/packages/agent-base/src/index.ts#L29C1-L29C49

Perhaps this is an issue with the bundler or configuration you are using?

@danielbankhead danielbankhead added type: question Request for information or clarification. Not an issue. external This issue is blocked on a bug with the actual product. and removed type: bug Error or flaw in code with unintended results or allowing sub-optimal usage patterns. labels Nov 28, 2023
@danielbankhead danielbankhead self-assigned this Nov 28, 2023
@noamolat-fs
Copy link

noamolat-fs commented Nov 30, 2023

Something similar happens on my end.
image

This is my code. I'm simply just importing the client.

import { OAuth2Client } from 'google-auth-library';

I'm using create-vue with Typescript with untouched configs for vite and TS.

@danielbankhead
Copy link
Contributor

@noamolat-fs this sounds like a bundler issue rather than an issue with this library. I’m not sure how else http.Agent wouldn’t exist here (referenced in the error message):

https://github.com/TooTallNate/proxy-agents/blob/b133295fd16f6475578b6b15bd9b4e33ecb0d0b7/packages/agent-base/src/index.ts#L29C1-L29C49

@noamolat-fs
Copy link

noamolat-fs commented Nov 30, 2023

@noamolat-fs this sounds like a bundler issue rather than an issue with this library. I’m not sure how else http.Agent wouldn’t exist here (referenced in the error message):

https://github.com/TooTallNate/proxy-agents/blob/b133295fd16f6475578b6b15bd9b4e33ecb0d0b7/packages/agent-base/src/index.ts#L29C1-L29C49

I'm having a hard time with what should I use. I've found these two libraries:

I was thinking that the issue above was a dependency issue so I switched to the latter, somehow I'm able to access it but now I have a problem with the global type for gapi. It's not being recognized by typescript even after installing @types/gapi but clearly there's a value for it.

I'm just trying to access a google account's profile information that's all. Am I correct to use the latter one or this library/repo would help me achieve the same?
I'm doing the requests in my Vue app with some sort of service scripts (typescript).

I switched to the last one because I thought the nodejs being referred was for the backend stuff and as mentioned I'm doing frontend.

Sorry for the unrelated subjects since I'm just trying to give a better insight into what I'm trying to do. Feel free to just focus on what's related.

@danielbankhead
Copy link
Contributor

I'm just trying to access a google account's profile information that's all. Am I correct to use the latter one or this library/repo would help me achieve the same?

I would recommend Google Sign in for this use case:

Related: We’re exploring alternative runtime support, including browsers, for this library. This will be useful for things like admin panels where the customer is a member of a GCP org. This can be tracked here:

@danielbankhead
Copy link
Contributor

Closing this as it appears to be a build tool issue unrelated to this library.

@danielbankhead danielbankhead closed this as not planned Won't fix, can't repro, duplicate, stale Nov 30, 2023
@noamolat-fs
Copy link

I'm just trying to access a google account's profile information that's all. Am I correct to use the latter one or this library/repo would help me achieve the same?

I would recommend Google Sign in for this use case:

Related: We’re exploring alternative runtime support, including browsers, for this library. This will be useful for things like admin panels where the customer is a member of a GCP org. This can be tracked here:

Thank you for pointing me in the right direction. I made it work 😁 !

@zieru
Copy link

zieru commented Jan 1, 2024

using this library only to make google-spreadsheet works by using JWT from service account, unfortunately I get this error too.
I don't have an idea why proxy agent get executed in the browser.

Building my own api call to get access_token from google is too much works.

@danielbankhead
Copy link
Contributor

@zieru

I don't have an idea why proxy agent get executed in the browser.

This library is currently is not designed for the browser. That can be tracked here:

For browser usage today, I would recommend:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
external This issue is blocked on a bug with the actual product. priority: p2 Moderately-important priority. Fix may not be included in next release. type: question Request for information or clarification. Not an issue. web
Projects
None yet
Development

No branches or pull requests

4 participants