mixpanel / mixpanel-js

Official Mixpanel JavaScript Client Library
https://mixpanel.com/help/reference/javascript
Other
886 stars 308 forks source link

unable to load the lib with Angular 2 #114

Open agustinhaller opened 7 years ago

agustinhaller commented 7 years ago

I've spent the whole day trying to load the module in my Angular 2 app as you describe in your examples/es2015-babelify/

I've tried everything and I keep getting error TS2307: Cannot find module ...

Can you please point me in the right direction?

I found a lot of people with the same issue as Angular 2 is becoming more and more popular. I think a clear guide/readme will help a lot the community.

Thanks!

tdumitrescu commented 7 years ago

@agustinhaller are you still having issues with this? AFAIK Typescript doesn't do anything unexpected with module resolution; you should be able to a 2015-style import with:

import mixpanel from 'mixpanel-browser/src/loader-module';
Silvercast commented 7 years ago
    (3,22): error TS2307: Cannot find module 'mixpanel-browser/src/loader-module'.

I got this instead

tahir-masood1 commented 7 years ago

I am also facing the same issue, did anyone found any solution to this, plz share :)

tdumitrescu commented 7 years ago

I just tried this out with the ng2 Hello World app from https://angular.io/docs/ts/latest/cli-quickstart.html and it works out of the box. The code I added to app.component.ts looks like this:

import mixpanel from 'mixpanel-browser/src/loader-module';

console.log('init mp');
mixpanel.init('FAKE TOKEN');
console.log('init mp succeeded');

From the sounds of it, maybe people on this thread aren't actually installing the mixpanel-browser library before trying to use it? To install it into node_modules and add it to your dependencies entry in package.json, run the following (inside the same directory as your project's package.json):

$ npm install --save mixpanel-browser

(I'm not sure if Angular 2 has some special ng command that does the same thing, but it's just installing a dependency from the NPM package repository.)

evanjmg commented 7 years ago

The solution above still doesn't work. Angularlytics2 has all of these methods => https://github.com/angulartics/angulartics2

tdumitrescu commented 7 years ago

If people would find it helpful, I'll make a sample Hello World that matches the above snippet so you can run it yourselves, but otherwise reports like this last one just don't provide enough information for us to do anything. "Cannot find module" is usually a pretty straightforward installation issue; it's looking for mixpanel-browser in node_modules and it isn't there.

basil2style commented 6 years ago

@tdumitrescu This works really great. Thank You very much

owenhope commented 6 years ago

I am having this same issue ... ive installed both the @types/mixpanel and mixpanel-browser

micky2be commented 6 years ago

Still seems to be very difficult to get mixpanel definition file loaded correctly