davide-scalzo / react-native-mixpanel

A React Native wrapper for Mixpanel tracking
MIT License
455 stars 195 forks source link

Undefined is not an object (evaluating '_reactNativeMixpanel.Mixpanel.sharedInstanceWithToken') #148

Closed jorge-sanz closed 5 years ago

jorge-sanz commented 6 years ago

I am getting this error with this code:

import { Mixpanel } from 'react-native-mixpanel';
...
Mixpanel.sharedInstanceWithToken(TOKEN);
Mixpanel.track("New order");

Any idea of how to solve it? Thank you so much! 🙂

syafiq90 commented 6 years ago

Mixpanel.default.sharedInstanceWithToken(TOKEN);

All must be Mixpanel.default

syafiq90 commented 6 years ago

please Fix this issue or update your Document @davodesign84

jorge-sanz commented 6 years ago

@syafiq90 it's working right now for me. Not sure how I fixed it. I restarted the project again.

SMJ93 commented 5 years ago

hey guys, we are getting the same issue:

Mixpanel.sharedInstanceWithToken("APIxxxxxx")

Error: `TypeError: Cannot read property 'sharedInstanceWithToken' of undefined.

Versions:

When console logging Mixpanel the functions show up as expected:

screen shot 2018-10-01 at 13 39 41

Let me know if you need any more info!

Cheers

SMJ93 commented 5 years ago

It looks like RNMixpanel is undefined in node_modules/react-native-mixpanel/index.js line 4:

const { RNMixpanel } = NativeModules

SMJ93 commented 5 years ago

I forgot to link it in xcode 🤦‍♂️:

Go to node_modules ➜ react-native-mixpanel and add RNMixpanel.xcodeproj In XCode, in the project navigator, select your project. Add libRNMixpanel.a to your project's Build Phases ➜ Link Binary With Libraries

paalex commented 5 years ago

import Mixpanel from 'react-native-mixpanel' instead of var Mixpanel = require('react-native-mixpanel') did it for me. The module now exports a default object and a MixpanelInstance object. Therefore, the above default import should be used or import {MixpanelInstance} from 'react-native-mixpanel' for the new (?) interface

fachrinfl commented 5 years ago

you can use like this, i found in file index.js:

const mixpanel = new MixpanelInstance(TOKEN)
await mixpanel.initialize()
mixpanel.track('my event')
nikodunk commented 5 years ago

My issue was not in the Javascript, but in this:

https://github.com/davodesign84/react-native-mixpanel/issues/50#issuecomment-258065688

SiddharthRana commented 4 years ago

Try to import without braces like :

import Mixpanel from 'react-native-mixpanel';