okotoki/mixpanel-figma

Library not working on a monorepo

andirsun opened this issue · 3 comments

I am using this library in a mono repository that contains these project:

  • Figma plugin
  • Next js Project

The library works great for figma project but when I try to run Next js project I am facing this error (probably is a server side enviroment).

error - ReferenceError: window is not defined
    at Object.<anonymous> (/Users/andirsun/projects/streamline/streamline-mono/node_modules/mixpanel-figma/mixpanel-patched.js:8:16)
    ...
    ...
    ...

So the error is happening here

// File mixpanel-patched.js
...
var window$1 = window;
...

The mixpanel team fixed this error with this lines

https://github.com/mixpanel/mixpanel-js/blob/1c4d98b4a485fbf4dc4421f00c33f3b19530b307/dist/mixpanel.cjs.js#L10

// since es6 imports are static and we run unit tests from the console, window won't be defined when importing this file
var window$1;
if (typeof(window) === 'undefined') {
    var loc = {
        hostname: ''
    };
    window$1 = {
        navigator: { userAgent: '' },
        document: {
            location: loc,
            referrer: ''
        },
        screen: { width: 0, height: 0 },
        location: loc
    };
} else {
    window$1 = window;
}

We have to upgrade this part of your patched library.
I pushed a PR with this Fix #5

Thanks for the fix @andirsun! Published in 2.0.3

@opudalo I discover a new error, please check it here #6