mixpanel-js icon indicating copy to clipboard operation
mixpanel-js copied to clipboard

unable to load the lib with Angular 2

Open agustinhaller opened this issue 7 years ago • 9 comments

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!

agustinhaller avatar Dec 05 '16 17:12 agustinhaller

@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';

tdumitrescu avatar Jan 04 '17 19:01 tdumitrescu

    (3,22): error TS2307: Cannot find module 'mixpanel-browser/src/loader-module'.

I got this instead

Silvercast avatar Jan 25 '17 22:01 Silvercast

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

tahir-masood1 avatar Apr 06 '17 06:04 tahir-masood1

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.)

tdumitrescu avatar Apr 06 '17 16:04 tdumitrescu

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

evanjmg avatar Aug 08 '17 10:08 evanjmg

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.

tdumitrescu avatar Aug 08 '17 15:08 tdumitrescu

@tdumitrescu This works really great. Thank You very much

basil2style avatar Oct 27 '17 14:10 basil2style

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

owenhope avatar Jul 05 '18 20:07 owenhope

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

micky2be avatar Jul 17 '18 07:07 micky2be