stripe-react-native: Expo managed workflow - crash on web
Describe the bug Importing dependencies from @stripe/stripe-react-native causes app to crash on Expo managed workflow - web.
To Reproduce Steps to reproduce the behavior:
- Create new expo managed workflow project
expo install @stripe/stripe-react-native- import stripe dependencies into component
- expo start --web
- See errors
Expected behavior No errors unless stripe components are actually used at runtime.
Additional context I’m aware that web isn’t supported, but it would be nice if it would at least build so I could run my app. I don’t plan to render any stripe components in the browser at runtime. Currently I can’t figure out a way to make Webpack exclude this dependency. Any help would be greatly appreciated.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 3
- Comments: 44
Let me make the steps explicit for the lazy folks like future me. (All credits to @robert-nash , in his previous answer.)
Add
null-loaderGenerate the
webpack.config.jsfile with expo’s template:Modify
webpack.config.js, add the line marked with the commentADD THIS LINE. Final version of the file should look like:I am still working through the first web build of my app but I seem to have got round this particular error for the meantime by adding null-loader as an alias for @stripe/stripe-react-native in my webpack config.
I added a webpack.config.js as described here and then modified it so it looks like this excerpt. I also installed the null-loader package.
webpack.config.jsNo. All the errors were introduced when I added the Stripe library.
@sfriedman-stripe No one here is asking you to support the web with your React Native SDK. It would be nice however if you made it so that having the SDK listed as a dependency in the package.json file doesn’t make the application crash when you run it in web mode. Until that has been fixed, I think you should leave this open.
@paulmbw @heinrichcoetzee
Sorry for the late response. When you make
stripe.native.jsandstripe.js, you just import/stripeand it will import the correct module depending on the environment where the code is run (web or mobile)For clarity, here are my files:
stripe.tsxstripe.native.tsxindex.tsThen you just import the
index.tsfile and the appropriate stripe file will be loaded depending on your environment. I think the reason I had anindex.tsfile was just so I could import from the folder instead of file, like/stripeinstead of/stripe/stripe, but if you don’t have a separatestripefolder then I think you can skip theindex.tsfile and just import/stripe.Sorry if this is confusing, if so let me know and I’ll try to clarify.
Hi all, we don’t plan on supporting the web with our React Native SDK. Please use Stripe.js if you are building a website. I will be closing this down. Please feel free to open a new issue if you have any further questions
I’ve asked the devs who maintain expo as well for guidance on this as I’m also running into this issue https://x.com/paulwaweruco/status/1797291557617340591
@JorensM I’ve tried your solution. I’ve got a
stripe.native.tsxfile which exports the actual stripe components/functions, and I’ve got astripe.web.tsxwith placeholders.I then import both files in a
StripeProviderand decide which file to render based on the Platform:I’m still running into the same error:
Is there something we might be missing?
This is seriously still an issue…
New solution works, but lazy TL;DR for anyone facing the problem on Expo Web (since webpack doesn’t seem to be supported anymore):
Preferably for a larger project, you might want to abstract out your Stripe functions instead, then make components that return the exact functionality (on mobile) or a dummied out function( on web), instead of maintaining two identical versions of your pages.
Relevant documentation on platform specific extensions here: https://docs.expo.dev/router/advanced/platform-specific-modules/#platform-specific-extensions
Awesome, thank you @JorensM !
I’ve written up a blog post to expand on this further, let me know if you have any questions
https://blog.launchtoday.dev/article/integrate-stripe-expo
I managed to solve this by using Platform extensions. I created a file
stripe.tsfor web which exports placeholder components/functions, and created a filestripe.native.tsfor mobile which exports the actual stripe components/functions. Now I can import by./stripeand it will automatically import the correct module based on which platform I’m using.hey guyzz for the stripe issue you can initially add null loader like this to resolve the TextInputState Error here is my webpackConfig.js file for adding alias
and create a separate NullModuleloader file like this

@anabeatrizzz
Facing this issue too, the fix posted by @robert-nash / @MehmetKaplan is not working for me.
@olaurendeau I have a workaround for now. I’ve implemented separate application entry points for mobile and web, with a basic dependency injection container to abstract away the platform dependent components. It’s not ideal, but it works.