-
Notifications
You must be signed in to change notification settings - Fork 27
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
Does not work on the Edge [Cloudflare Pages] #67
Comments
I don't think the library supports other runtimes than Node.js at the moment. And isn't Cloudflare Pages meant for static content? Wouldn't you need Cloudfare Workers instead? |
@weyert Cloudflare Pages has been capable of running server-side apps using Workers for some time now (competing against Vercel and the likes). As it currently stands, posthog doesn't work with Workers or any non-node runtime which is a bummer. The biggest issue appears to be the use of the
With many more alternative runtimes gaining traction (deno, bun, Fastly V8 etc.), I'd suggest switching out the crypto library. |
Having the same issue with |
@3x071c If you switch out crypto for Webcrypto which would need to be polyfilled for Node v14. Wouldn't you still have issues with Axios? |
We're using PostHog with It only works with esbuild, but I see that's what you're using as well. @weyert PostHog takes a new PostHog({
fetch: (...args) => fetch(...args)
}) |
I have verified that this works in Next.js, but I'm not 100% sure this will work in Cloudflare Pages, so it would be nice if someone could verify it works in the latest version. Please make sure to use: new PostHog({
fetch: (...args) => fetch(...args)
}) |
Just FYI—you need to make sure to use new PostHog(environment.POSTHOG_TOKEN, {
fetch: fetch.bind(globalThis)
});
// Your work here
const response = await fetch("https://www.google.com");
context.waitUntil(posthog.shutdownAsync());
return response; |
Bug description
Hello, I am trying to use posthog-node on the backend of Cloudflare pages.
How to reproduce
Related sub-libraries
Additional context
This is the log I get when Cloudflare tries to build my app for its environment:
The text was updated successfully, but these errors were encountered: