googleapis / google-api-nodejs-client

Google's officially supported Node.js client library for accessing Google APIs. Support for authorization and authentication with OAuth 2.0, API Keys and JWT (Service Tokens) is included.
https://googleapis.dev/nodejs/googleapis/latest/
Apache License 2.0
11.27k stars 1.91k forks source link

Fatal error when import `{calendar}` from '@googleapis/calendar' #3360

Open albertpratomo opened 9 months ago

albertpratomo commented 9 months ago

Environment details

Steps to reproduce

  1. import{calendar}from '@googleapis/calendar'
  2. This error shows up in the browser console, and the Vue 3 app doesnt load at all:

    index.ts:29 Uncaught TypeError: Class extends value undefined is not a constructor or null
    at node_modules/.pnpm/agent-base@7.1.0/node_modules/agent-base/dist/index.js (index.ts:29:42)
    at __require (chunk-6TJCVOLN.js?v=9bec359e:4:50)
    at node_modules/.pnpm/https-proxy-agent@7.0.2/node_modules/https-proxy-agent/dist/index.js (index.ts:7:1)
    at __require (chunk-6TJCVOLN.js?v=9bec359e:4:50)
    at node_modules/.pnpm/gaxios@6.1.1/node_modules/gaxios/build/src/gaxios.js (gaxios.ts:33:1)
    at __require (chunk-6TJCVOLN.js?v=9bec359e:4:50)
    at node_modules/.pnpm/gaxios@6.1.1/node_modules/gaxios/build/src/index.js (index.ts:15:1)
    at __require (chunk-6TJCVOLN.js?v=9bec359e:4:50)
    at node_modules/.pnpm/gcp-metadata@6.0.0/node_modules/gcp-metadata/build/src/index.js (index.ts:8:1)
    at __require (chunk-6TJCVOLN.js?v=9bec359e:4:50)
alexander-fenster commented 9 months ago

Hi @albertpratomo,

Just to double check - are you using the library in browser? How exactly - is it webpack or something else?

We don't officially support using these libraries in browser. Having that said, it's technically possible, but it will require some tweaks. If you happen to use webpack, this config file https://github.com/googleapis/google-api-nodejs-client/blob/main/src/apis/calendar/webpack.config.js will give you an idea which modules to block from getting into the bundle (specifically, https-proxy-agent should not get there).

albertpratomo commented 8 months ago

Yeah in the browser. I'm using Vite.

Okay I will try to exclude those packages from the bundle, let me try

stevau5 commented 7 months ago

Any luck @albertpratomo ?

anatoliykmetyuk commented 7 months ago

Same problem when having this line:

  const oauth2Client = new google.auth.OAuth2();

My setup is Vite and React.

@alexander-fenster if these are not the right libs to use from a browser, then which libs should we use from a browser to interact with the Google API?

chepoluis commented 6 months ago

Same problem with const oauth2Client = new google.auth.OAuth2();

Setup React and Vite. :/

ahostert commented 5 months ago

I have the same issue. Vite and Vue3 with Node 21.2.0

@googleapis_calendar.js?v=a78ca205:1027 Uncaught TypeError: Class extends value undefined is not a constructor or null at node_modules/gaxios/node_modules/agent-base/dist/index.js (@googleapis_calendar.js?v=a78ca205:1027:36) at __require (chunk-76J2PTFD.js?v=a78ca205:3:50) at node_modules/gaxios/node_modules/https-proxy-agent/dist/index.js (@googleapis_calendar.js?v=a78ca205:1232:24) at require (chunk-76J2PTFD.js?v=a78ca205:3:50) at node_modules/gaxios/build/src/gaxios.js (@googleapis_calendar.js?v=a78ca205:1355:31) at require (chunk-76J2PTFD.js?v=a78ca205:3:50) at node_modules/gaxios/build/src/index.js (@googleapis_calendar.js?v=a78ca205:1653:20) at require (chunk-76J2PTFD.js?v=a78ca205:3:50) at node_modules/gcp-metadata/build/src/index.js (@googleapis_calendar.js?v=a78ca205:3654:20) at require (chunk-76J2PTFD.js?v=a78ca205:3:50)

tspython commented 5 months ago

has anyone figured it out? i get the same issue with another google api

hruthik-bionic commented 4 months ago

I'm having the same issue with the youtube api with Nuxt js

oefeningen commented 3 months ago

Same error trying to use google drive api with quasar.js and vite