CommonJS import error
Related to https://github.com/microsoft/TypeScript/issues/45813
using the import syntax with mixpanel and typescript 4.4+ fails
import { disable, init } from "mixpanel-browser";
init("my_mixpanel_token");
disable();
^
TypeError: Cannot read property '_flags' of undefined
using the default import works well though, but it is discouraged by linting rules such as https://github.com/import-js/eslint-plugin-import/blob/v2.25.2/docs/rules/no-named-as-default-member.md
import mixpanel from "mixpanel-browser";
mixpanel.init("my_mixpanel_token");
mixpanel.disable();
Yeah, the export of the commonjs module is a Mixpanel library instance. It won't work to call individual methods without any binding to their instance.
Yeah, the export of the commonjs module is a Mixpanel library instance. It won't work to call individual methods without any binding to their instance.
So would you suggest using the default import instead? Also worthy of a contribution to definitelyTyped so other TS devs don't make this mistake
Yes, the default export should work for you. It's the only one we document. I think it might be a pretty simple update for the lib to export a named version as well so you could do
import {mixpanel} from 'mixpanel-browser';