Skip to content

TypeError: url_1.URLSearchParams is not a constructor #14

Description

@ThijsOnGitHub

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:

  1. 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'

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions