infinum / datx

DatX is an opinionated JS/TS data store. It features support for simple property definition, references to other models and first-class TypeScript support.
https://datx.dev
MIT License
140 stars 7 forks source link

Make datx work with native fetch on node 20 / drop use of `isomorphic-fetch` #1208

Open fvoska opened 11 months ago

fvoska commented 11 months ago

Relevant version

Relevant libraries

Breaking change

No

Description

isomorphic-fetch is used both in DatX unit tests and in any apps that might use datx on server-side. This lib is 3 years old and I would not consider it safe for production, from security perspective.

In node 20, we have experimental native fetch API and it is stable in 21. We should look into using that for all apps that are running node >=21 (so I guess when we switch to 22 LTS would be the ideal time). I have tried using fetch on some app I am working on that runs datx unit tests in node and it does not work. Simply removing the use of fetch from isomorphic-fetch and using native fetch causes this error:

image

Note: jsonapi-angular is not affected, because there we connect fetchReference to Angular's HttpClient (which in the background uses native XHR in the browser and xhr2 in node)