Amplitude-JavaScript icon indicating copy to clipboard operation
Amplitude-JavaScript copied to clipboard

Broken typescript import in all 6.* versions of amplitude-js

Open rskvazh opened this issue 4 years ago • 4 comments

Hi. Seems we can not import amplitude-js in typescript anymore after upgrading to 6.* In 5.* that worked fine:

import amplitude, { AmplitudeClient } from 'amplitude-js'
const amp = amplitude.getInstance()

In 6 version there is an webpack import error about getInstance is not a function.

PS. Latest @types/amplitude-js is only for 5.*

rskvazh avatar May 24 '20 10:05 rskvazh

I was encountering the same issue with [email protected] but found reference to this comment.

/**
   * Legacy API of Amplitude SDK - instance manager. Wraps around the current amplitude-client.js which provides more features
   * Function calls directly on amplitude have been deprecated. Please call methods on the default shared instance: amplitude.getInstance() instead.
   * See [Readme]{@link https://github.com/amplitude/Amplitude-Javascript#300-update-and-logging-events-to-multiple-amplitude-apps} for more information about this change.
*/

Before: import * as amplitude from "amplitude-js";

After: import { default as amplitude } from "amplitude-js";

Note that the readme link there does not work.

adamtay avatar Sep 13 '20 22:09 adamtay

Seems like this is still an issue. I am building some tooling around our Amplitude implementation and have all of a sudden been faced with this problem.

In package.json: "@types/amplitude-js": "6.0.0"

And in my file Im getting in the client: import {AmplitudeClient} from "amplitude-js";

And when using it I get an error. file.ts:53:35 - error TS2339: Property 'getInstance' does not exist on type 'AmplitudeClient'.

amplitude.getInstance().logEvent(eventType, eventProperties);

Shouldn't @types/amplitude-js be upgraded?

mijohansen avatar Oct 14 '20 20:10 mijohansen

Thanks for the bump on this issue! unfortunately the types are community owned so we have less agency to make this upgrade - but we'll work to get the types upgraded for the 7.x packages!

kelvin-lu avatar Oct 14 '20 20:10 kelvin-lu

This is working for amplitude-js 8.5.0, but not working for amplitude-js 8.19.0. Is there a way to fix this issue without downgrading the amplitude-js to 8.5.0?

gayancharith avatar Oct 07 '22 07:10 gayancharith