FG
๐Ÿ”Œ APIs & SDKsStripe

Importing Stripe via ES Modules does not respect monkey-patching 'http'

Freshover 2 years ago
Mar 14, 20260 views
Confidence Score87%
87%

Problem

Describe the bug When trying to mock responses made with stripe-node in a Node.js enviroment, the requests hit the real server instead of getting caught by MSW. To Reproduce You can copy and paste the code below. (Either write actual handlers for your `stripeHandlers`, or you can leave them out, as we did below. If you want to try it out with handlers, simply spread them into `setupServer`.) Sine we configured `onUnhandledRequest: 'warn'` MSW should log out to the console when requests are uncaught. The manual method with `axios` works correctly and logs out this warning / reacts when you configure handlers. However, the second (in the code blocked `skip`ped) test does NOT log out this warning and simply hits the servers. [code block] [code block] Expected behavior MSW can intercept the Stripe requests. I assume this library does HTTP requests somehow esoterically, so it would be nice to learn how it does it, so that we can get MSW to work. Code snippets _No response_ OS macOS Node version 18.6.0 Library version stripe-node v12.12.0 API version 2022-11-15 Additional context _No response_

Unverified for your environment

Select your OS to check compatibility.

1 Fix

Canonical Fix
Moderate Confidence Fix
84% confidence100% success rate2 verificationsLast verified Mar 14, 2026

Solution: Importing Stripe via ES Modules does not respect monkey-patching 'http'

Low Risk

Turns out https://github.com/stripe/stripe-node/pull/1854 is not viable because `esModuleInterop: true` is a breaking change and not recommended for libraries to enable. I think we can still find a way to make a similar idea work but we won't land it today as expected.

84

Trust Score

2 verifications

100% success
  1. 1

    Turns out https://github.com/stripe/stripe-node/pull/1854 is not viable because

    Turns out https://github.com/stripe/stripe-node/pull/1854 is not viable because `esModuleInterop: true` is a breaking change and not recommended for libraries to enable.

  2. 2

    I think we can still find a way to make a similar idea work but we won't land it

    I think we can still find a way to make a similar idea work but we won't land it today as expected.

Validation

Resolved in stripe/stripe-node GitHub issue #1844. Community reactions: 1 upvotes.

Verification Summary

Worked: 2
Last verified Mar 14, 2026

Sign in to verify this fix

Environment

Submitted by

AC

Alex Chen

2450 rep

Tags

stripepaymentsapibug