node-google-spreadsheet icon indicating copy to clipboard operation
node-google-spreadsheet copied to clipboard

There is a TypeError saying URL is not a constructor, from gaxios dependency. Someone please help me.

Open ManojaD2004 opened this issue 10 months ago ā€¢ 14 comments

I have used google-auth-library, JWT auth for auth. Just yesterday it was working, today it is not.

https://theoephraim.github.io/node-google-spreadsheet/

Followed everything that was there in this docs. Also Iā€™m using nextjs.

ManojaD2004 avatar Apr 16 '24 13:04 ManojaD2004

Same here, using Cypress

gusintheeshell avatar Apr 17 '24 20:04 gusintheeshell

Same here. I found out that google-auth-library cause this problem. It has dependency gaxios and invoke method https://github.com/googleapis/gaxios/blob/main/src/gaxios.ts#L191 with uppercase method URL, but it invoked in lowercase. I changed it directly in node_modules and it works. Now we need to wait for fix from google

nikfakel avatar Apr 22 '24 03:04 nikfakel

Any update on this fix ? Facing this issue -

Error appending row: TypeError: url_1.URL is not a constructor
    at Gaxios._Gaxios_urlMayUseProxy (gaxios.js:274:23)
    at Gaxios._Gaxios_prepareRequest (gaxios.js:398:105)
    at Gaxios.request (gaxios.js:104:99)
    at DefaultTransporter.request (transporters.js:65:30)
    at GoogleToken._GoogleToken_requestToken (index.js:241:42)
    at GoogleToken._GoogleToken_getTokenAsyncInner (index.js:180:97)
    at GoogleToken._GoogleToken_getTokenAsync (index.js:160:173)
    at GoogleToken.getToken (index.js:110:102)
    at JWT.refreshTokenNoCache (jwtclient.js:173:36)
    at JWT.refreshToken (oauth2client.js:166:24)
    at JWT.getRequestMetadataAsync (oauth2client.js:312:28)
    at JWT.getRequestMetadataAsync (jwtclient.js:95:26)
    at JWT.getRequestHeaders (oauth2client.js:275:37)
    at U (index.mjs:37:21941)
    at C._setAxiosRequestAuth (index.mjs:37:23000)
    at async Axios.request (Axios.js:49:14)
    at async C.loadInfo (index.mjs:37:25258)

v29neil avatar May 01 '24 10:05 v29neil

Had the same issue, changed version to 9.7.0 and it works. (thanks for the hint that the issue happened 3 weeks ago)

MrBadIvan avatar May 04 '24 19:05 MrBadIvan

Same here. I found out that google-auth-library cause this problem. It has dependency gaxios and invoke method googleapis/gaxios@main/src/gaxios.ts#L191 with uppercase method URL, but it invoked in lowercase. I changed it directly in node_modules and it works. Now we need to wait for fix from google

@nikfakel can you please describe what you changed directly in node_modules?

Had the same issue, changed version to 9.7.0 and it works.

This doesn't fix it for me - @MrBadIvan did you do something extra except setting it to 9.7.0 and then npm / yarn install again? - I checked the package.json in node_modules and it's 9.7.0 but it's still creating the same Error.

TimKraemer avatar May 08 '24 21:05 TimKraemer

@TimKraemer I changed this

  • const candidate = new url_1.URL(url);
  • const candidate = new url_1.Url(url);

And then I saved changes with patch-package, so CI/CD can keep this changes too

Now I got that this is no some bug, this package has to work on NodeJS and not considered to work in browser. So you can use just as is.

nikfakel avatar May 12 '24 18:05 nikfakel

did you do something extra except setting it to 9.7.0 and then npm / yarn install again?

Nope =/

MrBadIvan avatar May 12 '24 19:05 MrBadIvan

Hey, I fixed it. Sorry for my late reply.

Basically I just copied the code and ran it in nodejs, instead of client side javascript. And it worked perfectly. šŸ‘

Note: I still managed to run this on nextjs, not on pages though, but in the form of an api.

ManojaD2004 avatar May 13 '24 02:05 ManojaD2004

@TimKraemer I changed this

  • const candidate = new url_1.URL(url);

  • const candidate = new url_1.Url(url);

Thank you! This is the only thing, that worked for me (I also had to remove my .next folder to kill the cached module).

TimKraemer avatar May 13 '24 11:05 TimKraemer

First of all. I tried to use patch-package to manage the error. But i dunno I'm using for Adobe Experience Manager purposes, but still having the gaxios URL typo.

Any updates of this issue?

uzumis avatar May 23 '24 21:05 uzumis

@uzumis I use command (in package.json "scripts" to start server like this "dev": "npx patch-package && next dev" before it I created patch with patch-package

nikfakel avatar May 23 '24 21:05 nikfakel

@nikfakel Works like a charm.

before the patch package i use npm clean first to assure the patch will be applied with no problem. My issue is solved for now. Thanks

uzumis avatar May 24 '24 14:05 uzumis

I've also experienced this and apart from directly hardcoding a fix in node_modules šŸ™ˆ, I didn't know what else to do. I will try patching the package as you suggested @nikfakel.

I did notice that it appeared to have been raised (and fixed?) already in this commit: https://github.com/googleapis/gaxios/pull/45/files#diff-1fbac0bfbd160f817d8a77140897b06cb53ff95f317bc9c3345afe4605fb3978

To fix it, if you look at the top of gaxios.ts there are some helper functions to detect information about the environment in which it's running -it would be simple to add another similar function or maybe make use of hasWindow() to work out whether to use the node URL module or window.url.

Anyway, I thought about creating a pull request but I hesitated as it looked like it had at some point already been done - and maybe removed again for a reason?

clare-lindley avatar Jun 18 '24 13:06 clare-lindley