Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doesn't work in cloudflare workers #158

Closed
Munter opened this issue Mar 22, 2021 · 4 comments
Closed

Doesn't work in cloudflare workers #158

Munter opened this issue Mar 22, 2021 · 4 comments
Labels
bug Something isn't working v6 Getting addressed or related to version 6 of the kit

Comments

@Munter
Copy link

Munter commented Mar 22, 2021

This library uses cross-fetch to polyfill fetch in the environments it runs in.

However, cross-fetch is not a proper polyfill. It replaces the native fetch with a polyfill based on XMLHttpRequest no whether fetch or XMLHttpRequest exist or not.

In Cloudflare workers you are limited to a web worker context, which has a very limited subset of javascript API available. In this environment you have fetch, but not XMLHttpRequest. So cross-fetch breaks the environment by clobbering the native fetch with a version that throws because XMLHttpRequest doesn't exist.

The same thing happens if I try to run the prismic client in a web worker or a serviceworker.

See also lquixada/cross-fetch#69

@lihbr
Copy link
Member

lihbr commented Mar 22, 2021

Hey @Munter, thanks for opening an issue, that's an interesting one!

We'll have a look at it, in the meantime, I can suggest you having a look at ts-prismic which is a lower level Prismic client that allows you to pick your query library 🙂

cc @Duaner

@lihbr lihbr added bug Something isn't working v6 Getting addressed or related to version 6 of the kit labels Jun 21, 2021
@lihbr
Copy link
Member

lihbr commented Jun 21, 2021

Hey @Munter, just letting you know we published @prismicio/client v6 in alpha, allowing you to provide your own fetcher function 🎉

While not documented yet the new kit has a very similar usage and comes with built-in tsdoc and an examples folder to already help you integrate with it ☺️

https://github.com/prismicio/prismic-javascript/tree/aa/v6/examples

https://github.com/prismicio/prismic-javascript/blob/3dfba0f4fb013421db58217cb02a810dab2b5fcc/src/client.ts#L145-L148

@lihbr
Copy link
Member

lihbr commented Oct 12, 2021

Hey @Munter, I'm happy to announce we just released in beta @prismicio/client and @prismicio/helpers (the new prismic-dom). Stable release is scheduled for November!

@prismicio/client is now free of cross-fetch, you can even provide your own fetch implementation, so I figured out you'd be interested! You can read more about how to give them a try here, your feedback is also very much appreciated~

Cheers!

@lihbr
Copy link
Member

lihbr commented Jan 5, 2022

Fixed in v6 🎉 Thank you for your contribution!

https://prismic.io/docs/technical-reference/prismicio-client?version=v6

If you're still experiencing the issue with the new kit, feel free to reopen!

@lihbr lihbr closed this as completed Jan 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working v6 Getting addressed or related to version 6 of the kit
Projects
None yet
Development

No branches or pull requests

2 participants