janhommes / o.js

o.js - client side oData lib.
https://janhommes.github.io/o.js/example/
MIT License
238 stars 57 forks source link

Not compatible with node v18.2.0? #135

Closed kerubkim closed 2 years ago

kerubkim commented 2 years ago

I was using this package before I updated to a new node version. After the update I am currently getting TypeError: Referrer "client" is not a valid URL.

Odata example: const result = o("some-external-api-url", { headers: { Authorization: 'Bearer ${accessToken}', }, fragment: "", // fragment defaults to "value" which just returns the data });

Node: v18.2.0 odata: ^1.3.1

manuelseeger commented 1 year ago

Any input on how you fixed this? I am getting the same error just with the example from the Readme

manuelseeger commented 1 year ago

For anyone getting this error with Node > v18 and native fetch based on undici, it appears you need to set the referrer yourself:

const url = "https://services.odata.org/V4/Northwind/Northwind.svc/"; const config = { referrer: new URL("client", "http://localhost").toString(), }; const northwind = o(url, config);

const data = await northwind.get("Products").query({ $top: 1 });