prezly/javascript-sdk

Error with "url" dependency when using SDK in the browser

kamilmielnik opened this issue · 0 comments

I'm getting this error when trying to use sdk in the browser environment:

ApiError.js?3976:20 Uncaught (in promise) Error: API Error (0): url_1.URL is not a constructor
    at new ApiError (ApiError.js?3976:20)
    at Object.eval (createRequest.js?b0f4:138)
    at step (createRequest.js?b0f4:44)
    at Object.eval [as next] (createRequest.js?b0f4:25)
    at eval (createRequest.js?b0f4:19)
    at new Promise (<anonymous>)
    at __awaiter (createRequest.js?b0f4:15)
    at Object.createRequest [as default] (createRequest.js?b0f4:91)
    at Object.get (Api.js?fab1:11)
    at ApiClient.get (ApiClient.js?2844:25)
    at NewsroomLanguages.eval (NewsroomLanguages.js?6a02:77)
    at step (NewsroomLanguages.js?6a02:33)
    at Object.eval [as next] (NewsroomLanguages.js?6a02:14)
    at eval (NewsroomLanguages.js?6a02:8)
    at new Promise (<anonymous>)
    at __awaiter (NewsroomLanguages.js?6a02:4)
    at NewsroomLanguages.get (NewsroomLanguages.js?6a02:71)
    at <anonymous>:1:49

It's because of this import:

import { URL } from 'url';


I think we need to do something like this: https://stackoverflow.com/a/58232594