Open DZetko opened 2 weeks ago
When you see this error this is caused by either of the following
Personally, I've only seen the first case where a combination of npm
and snippet
was being used, so your local code is including 1 copy of the source code and using that, but the SDK Loader comes along behind you and "overwrites" the global namespace of the code "Microsoft.ApplicationInsights.XXX".
The latest version of the code (v3.x) is aware of this situation and the default "initialization" code added to the top of each bundle trys to avoid "overwriting" the class / object definitions. By
Microsoft.ApplicaitonInsights3
and then it "populates" the Microsoft.ApplicationInsights
Microsoft.ApplicationInsights
class / object name if it's not present (first write wins)Microsoft.Application.__ms$mod__
which identifies the "order" of the SDK's being loaded and which version was used to populate the root namespace. (But this is only added if you are loading from the CDN as it's part of the UMD heading (see all of that code at the top with var names of baseNs
, modName
etcSo what does all this mean?
Please check whether your runtime is
npm
but then something is also injecting the SDK Loader and you end up loading (and replacing) the SDK instance (F12 - network tab is your friend for this one)apply
or call
) rather than via the normal initialized object instances. Sometimes just creating a "dummy" SDK instance (so that the dynamic prototype stubs are populated) is enough (other times not) - we play this game with some of our tests. The easiest solution is to just initialize and call the functions directly.
Description/Screenshot I have below React component
` import React from "react"; import { useAppInsightsContext } from "@microsoft/applicationinsights-react-js"; const TestComponent = () => { const { trackEvent } = useAppInsightsContext();
}; export default TestComponent; `
When I click the Add Number button, I am getting bellow error message:
My Application Insights instance is set up as below
Steps to Reproduce
Expected behavior Error should not be displayed and event should be sent to Application Insights.
Additional context Add any other context about the problem here.
When using reactPlugin instance directly and calling
reactPlugin.trackEvent
works.