Cannot read property 'init' of undefined for stripe.init()
See original GitHub issueI am successfully using this library on Android with no problems. On iOS, I cannot get past this error. I have tried to follow all of the other fixes in the other bug report threads with similar issues to no avail. (#102, #53, #81) This includes reinstalling the project and starting from scratch several times. Using the instructions with Pods and manually. I have installed the example project and got it working. This has never been an Expo project. The library links and appears to be working until I try to initialize it with stripe.init().
`import stripe from ‘tipsi-stripe’; console.log(‘STRIPE’, stripe);
stripe.init({ publishableKey: ‘pk_test_xxxx’ });`
This console log shows that it is there but when I actually try to use it, it says it is undefined.
STRIPE Stripe {stripeInitialized: false, init: function, deviceSupportsApplePay: function, canMakeApplePayPayments: function, paymentRequestWithApplePay: function…}canMakeApplePayPayments: function ()cancelApplePayRequest: function ()completeApplePayRequest: function ()createSourceWithParams: function ()createTokenWithBankAccount: function ()createTokenWithCard: function ()deviceSupportsApplePay: function ()init: function ()openApplePaySetup: function ()paymentRequestWithApplePay: function ()paymentRequestWithCardForm: function ()stripeInitialized: true__proto__: Object ExceptionsManager.js:65 Cannot read property 'init' of undefined
If I run stripe.init() without any arguments which makes it fail as it should, I get this error:
ExceptionsManager.js:65 Failed options type: The options publishableKey
is marked as required in Stripe.init
, but its value is undefined
.
What is going on?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:1
- Comments:9 (1 by maintainers)
Top GitHub Comments
I agree you should follow the installation guide as that seems to work for most people but I tried both methods (pod and manual) and it didn’t copy over the header search paths it needed to build properly. It will build but it doesn’t get put into ‘NativeModules’ so it isn’t there when tipsi-stripe tries to pull it out and you get the undefined or null type error when you try to use it.
Using this screen as a guide, you need to make sure the bottom one is on your list in the Header Search Paths. If you are new to Xcode, click on the folder at the top left of the left pane. This will bring you back to your project folder. Click on the folder at the top that has your project name (be careful you aren’t on a sub-project folder as they also have all these settings), go to Build Settings in the center panel. Look here for reference of what it should look like. There will probably be lots of things in this so just do a search in the top right corner of the center panel for ‘header search paths’ or something similar and go to the results. Click on the paths section and it will pop up this little dialog (like in the first link) to allow you to edit them. You can either type it in manually or with Finder open you can drag the node_modules>tipsi-stripe>ios>TPSStripe folder into this dialog and it will link them itself.
That was what solved it for me. Apologies if any of these instructions are inaccurate as I’m doing it from memory as I’m not at work. Hopefully this fixes it for you.
Also, when in doubt clean your build and or build folders.
@Genericjam Can you give me some help here please? It’s been so many hours working on this and I still can’t get it working…