googleapis / google-auth-library-nodejs

🔑 Google Auth Library for Node.js
Apache License 2.0
1.73k stars 381 forks source link

Class extends value undefined is not a constructor or null #1632

Closed frama21 closed 1 year ago

frama21 commented 1 year ago

Environment details

Steps to reproduce

  1. I Install the google-auth-library in nuxtjs 3 with vite
  2. then i make the separate helper call spreadsheet.ts for calling the method when i need it
  3. this my inside spreadsheet.ts image
  4. then i import spreadsheet.ts in another file to hit the method & i got the error like this image

when i comment the const client the error is not showing

danielbankhead commented 1 year ago

@frama21 this looks more like an issue with the bundler or agent-base rather than this library (looking at the first line of the error).

danielbankhead commented 1 year ago

I cannot seem to reproduce this issue - let me know if there's a specific line or class in the auth library I can assist in debugging.

phalla-doll commented 8 months ago

I'm having the same error with my Angular 17 project.

Step to reproduce:

  1. Install the Angular 17 version
  2. Install google-auth-library (latest version is 9.6.3)
  3. import {JWT} from "google-auth-library";

const serviceAccountAuth = new JWT({});

giantpenguin commented 2 weeks ago

Is it the issue caused by the (google-auth-library) library still uses the require while others (e.g., @googleapis/sheets v4 or a vuejs component) depend on it have been changed to use the import for modules loading?

Uncaught (in promise) TypeError: Class extends value undefined is not a constructor or null at node_modules/google-auth-library/build/src/auth/authclient.js (authclient.js:31:35) at require (chunk-WMTNK64S.js?v=40045171:15:50) at node_modules/google-auth-library/build/src/auth/oauth2client.js (oauth2client.js:22:22) at __require (chunk-WMTNK64S.js?v=40045171:15:50) at node_modules/google-auth-library/build/src/auth/computeclient.js (computeclient.js:19:24) at require (chunk-WMTNK64S.js?v=40045171:15:50) at node_modules/google-auth-library/build/src/auth/googleauth.js (googleauth.js:36:25) at __require (chunk-WMTNK64S.js?v=40045171:15:50) at node_modules/google-auth-library/build/src/index.js (index.js:17:22) at __require (chunk-WMTNK64S.js?v=40045171:15:50)

in this case the events_1 is null due to the events module has not been imported/loaded

const events_1 = require("events"); ... class AuthClient extends events_1.EventEmitter { constructor(opts = {}) { ...

There is no reference to "events" package in https://github.com/googleapis/google-auth-library-nodejs/blob/main/package.json. Where I can get the "events" module/package @danielbankhead?

giantpenguin commented 2 weeks ago

Seeing many warning message in the terminal at building the vue app, many lines from google-auth-library likes

[plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "os" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/google-auth-library/build/src/auth/googleauth.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/google-auth-library/build/src/auth/refreshclient.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "querystring" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/google-auth-library/build/src/auth/oauth2client.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "fs" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/gtoken/build/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "path" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/gtoken/build/src/index.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "http2" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/googleapis-common/build/src/http2.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "zlib" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/googleapis-common/build/src/http2.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details. [plugin:vite:resolve] [plugin vite:resolve] Module "url" has been externalized for browser compatibility, imported by "[root_folder]/node_modules/googleapis-common/build/src/http2.js". See https://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.

I realize that it is issue relates to https://vite.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility