Unusable in Cloudflare workers due to use of node specific APIs/packages
See original GitHub issueDescribe 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
increateNodeHttpClient
- 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!
Issue Analytics
- State:
- Created a year ago
- Comments:14 (4 by maintainers)
Top Results From Across the Web
Node.js support in Cloudflare Workers
Check out the current state of Node.js compatibility with Workers. We want to hear from you on which Node.js-dependent libraries and APIs we ......
Read more >Security model · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment ...
Read more >A Node to Workers Story - The Cloudflare Blog
In this article I will breeze through a simple example of how converting a former Node server into a Worker untangled a part...
Read more >Configuration · Cloudflare Workers docs
Documentation for Cloudflare Workers, a serverless execution environment that allows you to create entirely new applications or augment ...
Read more >JavaScript modules are now supported on Cloudflare Workers
Now you can use JavaScript modules, also known as ECMAScript or “ES” ... by most Web browsers, Node.js, Deno, and now Cloudflare Workers....
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Yea had to get inspiration from some other related issue comment, even though I’m doing the same with Mailjet 😅
So far the rest API is pretty straight forward if you have questions or anything let me know 🙌
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 💁🏼