TypeError: url_1.URLSearchParams is not a constructor
Describe the bug When I run this code i got this error:
Code run:
const wordpressClient = new WordpressClient();
const posts = await wordpressClient.post().find()
With the following class, and wordpress is running on localhost:80
export class WordpressClient extends WpApiClient{
constructor() {
super("http://localhost");
}
post<P = WPPost<WordpressPost>>(): DefaultEndpointWithRevision<P> {
return super.post<P>()
}
}
Uncaught (in promise) TypeError: url_1.URLSearchParams is not a constructor
at WordpressClient.createEndpointGet (wp-api-client.js:40:48)
at WordpressClient.defaultEndpoints (wp-api-client.js:103:24)
at WordpressClient.addPostType (wp-api-client.js:112:21)
at WordpressClient.post (wp-api-client.js:181:21)
at WordpressClient.post (WorpressClient.ts:10:22)
at loadPosts (useWordpressData.ts:15:45)
at useWordpressData.ts:44:9
at commitHookEffectListMount (react-dom.development.js:23150:26)
at commitPassiveMountOnFiber (react-dom.development.js:24926:13)
at commitPassiveMountEffects_complete (react-dom.development.js:24891:9)
To Reproduce Steps to reproduce the behavior:
- Run this code:
const posts = await wordpressClient.post().find()
Expected behavior Expected to load data
Desktop (please complete the following information):
- Browser: Chrome
Builder:
- React build with vite
Suggested change I got it locally fixed by removing
import { URLSearchParams } from 'url'
I got it locally fixed by removing
import { URLSearchParams } from 'url'
hey, thanks for reaching out. what NodeJS version are you using? i'll have to investigate this a bit more, but it seems like an easy fix. sadly i can't give you a time frame on the update, because i am currently undergoing a very strenuous medical treatment.
I use node version 16.13.0. And good luck with your medical treatment.
Hm, I have no issues with Node.js v16. Are you by any chance pulling in the "url" module in your webpack config?
Hi I'm having the same issue too - I'm using parcel.js rather than webpack and it is adding the "url" package to the package.json
same issue, node v20.2.0, Vite + Vue3
same issue, node v20.2.0, Vite + Vue3
Please see the other open issue - the author passed away.