Amplitude-JavaScript
Amplitude-JavaScript copied to clipboard
Broken typescript import in all 6.* versions of amplitude-js
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.*
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.
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?
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!
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?