I'm encountering a TypeError when making requests for a token from the googleapis
library using a JWT client. The error message is as follows:
TypeError: Class extends value #<child> is not a constructor or null
at lib/websocket/events.js (node:internal/deps/undici/undici:10194:52)
at __require (node:internal/deps/undici/undici:4:50)
at lib/websocket/util.js (node:internal/deps/undici/undici:10436:40)
at __require (node:internal/deps/undici/undici:4:50)
at lib/websocket/websocket.js (node:internal/deps/undici/undici:10979:96)
at __require (node:internal/deps/undici/undici:4:50)
...
at Gaxios.validateOpts (/home/ubuntu/xxx/node_modules/gaxios/build/src/gaxios.js:213:32)
The error seems to be related to the following code snippet:
const isFormData = typeof FormData === 'undefined'
? false
: (opts === null || opts === void 0 ? void 0 : opts.data) instanceof FormData;
Interestingly,
- the error disappears when all the references of
FormData
is removed. - the error only occurs for node version 18.18.2 and above except version 19.
This suggests a potential compatibility issue with the specific Node.js versions. Further investigation into the release notes indicates that this commit might have introduced the problem.
I have a few questions regarding this issue:
- How does the above error occur simply by referencing a token/variable using typeof?
- Based on the findings, can we conclude that this is an issue introduced in the Node.js package starting from version 18.18.2?
- Does this imply that the libraries involved (googleapis, gaxios, undici) are not compatible with these Node.js versions?
- What could be a possible solution for this, considering it appears to be a library-level issue?
Any insights or suggestions on resolving this issue would be greatly appreciated. Thanks!