question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Unusable in Cloudflare workers due to use of node specific APIs/packages

See original GitHub issue

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!

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:14 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
CanRaucommented, Dec 3, 2022

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 🙌

1reaction
CanRaucommented, Dec 2, 2022

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 💁🏼

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found