Unusable in Cloudflare workers due to use of node specific APIs/packages
Problem
Describe the bug This seems to be a broad regression, given that Cloudflare workers is supposed to be supported. The root of the issue is usage of node specific APIs and globals. - webhooks uses Buffer - not supported in workers, one workaround would be to wrap it in a try/catch and fall back to assuming the value is a string (or I guess just check if it exists and fall back) - utils requires `crypto` which is required early in stripe.ts - it's plausible that import could be replaced/polyfilled with Web Crypto - there's a few references to `http`/`https` in `createNodeHttpClient`- the compiler doesn't seem to be smart enough to skip compiling NodeHttpClient (I think since it's imported by default? It's possible that dynamically requiring it could help?) - somewhere there's `child_process` usage I was able to get things mostly working by using the package.json `browser` field to stub out the `crypto`(swapped for `crypto-js`)/`http`/`https`/`child_process`(swapped the others for an empty dummy.ts file) imports, but webhooks unchecked Buffer usage fully blocked me. To Reproduce I'll see if I can get a repro repo up but: - create a new cloudflare function - install stripe-node - observe many errors Expected behavior Everything should work! Code snippets _No response_ OS Ubuntu Node version 19 Library version 10.15.0 API version 22-08-01 Additional context I'm @cal on slack if chatting synchronously helps!
Unverified for your environment
Select your OS to check compatibility.
1 Fix
Solution: Unusable in Cloudflare workers due to use of node specific APIs/packages
yea def not gonna use a non-official fork, tho using a Worker in addition is interesting, but I think I switch our SvelteKit to use the Workers adapter instead and get logging as well ๐ค had a custom GitHub Actions pipeline planned anyway ๐๐ผ
Trust Score
2 verifications
- 1
yea def not gonna use a non-official fork, tho using a Worker in addition is int
yea def not gonna use a non-official fork, tho using a Worker in addition is interesting, but I think I switch our SvelteKit to use the Workers adapter instead and get logging as well ๐ค had a custom GitHub Actions pipeline planned anyway ๐๐ผ
Validation
Resolved in stripe/stripe-node GitHub issue #1593. Community reactions: 1 upvotes.
Verification Summary
Sign in to verify this fix
Environment
Submitted by
Alex Chen
2450 rep