XMLHttpRequest is not defined

I’m trying to use the following library (https://github.com/fauna/faunadb-js) to query my FaunaDB database (https://fauna.com) in a Cloudflare Worker.

However the package faunadb-js uses the cross-fetch (https://github.com/lquixada/cross-fetch) library and runs new XMLHttpRequest() which is giving me the XMLHttpRequest is not defined error in my worker.

Why can’t a worker use this function? Anybody have any idea how I can fix this issue? Thanks

1 Like

It’s super cool that you want to query Fauna from a Worker!

Workers use the Fetch API to support HTTP requests, not the XMLHttpRequest API which your library is using. Browsers support both, but Fetch is more modern.


Got it working @zack

Had to remove the cross-fetch package to get it working. Thanks for the info!