question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

See original GitHub issue

Encountered 6 errors when updating to v2.8.3 of @microsoft/applicationinsights-web (using tsc v4.6.4). These errors did NOT exist in v2.7.4, but do occur in all v2.8.x releases.


node_modules/@microsoft/applicationinsights-common/types/Enums.d.ts:8:101 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

8 export declare const StorageType: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eStorageType>;
                                                                                                      ~~~~~~~~~~~~

node_modules/@microsoft/applicationinsights-common/types/Enums.d.ts:34:113 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

34 export declare const DistributedTracingModes: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eDistributedTracingModes>;
                                                                                                                   ~~~~~~~~~~~~~~~~~~~~~~~~

node_modules/@microsoft/applicationinsights-common/types/Interfaces/Contracts/SeverityLevel.d.ts:14:103 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

14 export declare const SeverityLevel: import("@microsoft/applicationinsights-core-js").EnumValue<typeof eSeverityLevel>;
                                                                                                         ~~~~~~~~~~~~~~

node_modules/@microsoft/applicationinsights-core-js/types/JavaScriptSDK.Enums/EventsDiscardedReason.d.ts:33:111 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

33 export declare const EventsDiscardedReason: import("../JavaScriptSDK.Enums/EnumHelperFuncs").EnumValue<typeof eEventsDiscardedReason>;
                                                                                                                 ~~~~~~~~~~~~~~~~~~~~~~

node_modules/@microsoft/applicationinsights-core-js/types/JavaScriptSDK.Enums/LoggingEnums.d.ts:11:105 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

11 export declare const LoggingSeverity: import("../JavaScriptSDK.Enums/EnumHelperFuncs").EnumValue<typeof eLoggingSeverity>;
                                                                                                           ~~~~~~~~~~~~~~~~

node_modules/@microsoft/applicationinsights-core-js/types/JavaScriptSDK.Enums/LoggingEnums.d.ts:100:108 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.

100 export declare const _InternalMessageId: import("../JavaScriptSDK.Enums/EnumHelperFuncs").EnumValue<typeof _eInternalMessageId>;
                                                                                                               ~~~~~~~~~~~~~~~~~~~

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:2
  • Comments:8 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
MSNevcommented, Jun 8, 2022

@saranchonkau Can you post your tsconfig.json (or at the relevant settings (module, target, isolatedModules, skipLibCheck, etc) as I would not expect that just importing the ApplicationInsights module (should) cause the reference to be included.

And @Karlie-777 if you can please create a repro with the settings so that we can investigate further.

1reaction
MSNevcommented, May 27, 2022

No, at this point in time this is a won’t fix as we will not be removing the usage of const enums.

And because we consume and extend this ourselves internally, one or more of the work arounds above should work. Internally we don’t use isolatedModules and we have different usages of skipLibCheck, and based on readings it appears that if you directly import the const enums (which do appear to be exported when I looked) this should also work.

Please feel free to create a minimal repro that shows the issue and I can get someone to research into this a bit deeper for possible solutions / work arounds. I do know that we could stop using the EnumHelpers and manually create the objects, but this is problematic from a validation perspective as it would allow new values to be missed, where the current helpers where designed to break compiling when there was either a missed value or a typo for one of them.

I have refrained from tagging this as won’t fix, as I expected that at some point a future version of TypeScript may provide an option to more directly address this issue as we are not the only library that has hit this issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot access ambient const enums when the ...
ts:1193:6 - error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided. 1193 [BooleanFlags.shouldCast]?: ...
Read more >
Why is `const enum` allowed with `isolatedModules`?
error TS1209 : Ambient const enums are not allowed when the '--isolatedModules' flag is provided. My understanding of --isolatedModules is that ...
Read more >
Cannot access ambient const enums (when using create ...
I think this post explains the problem TypeScript: Don't Expor… ... ambient const enums when the '–isolatedModules' flag is provided'.
Read more >
ts-transformer-strip-const-enums v1.0.1
... exported from your library, because they will get an error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided...
Read more >
vite报错Cannot access ambient const enums when the
build时报错: Cannot access ambient const enums when the '–isolatedModules' flag is provided.26 readonly [ReactiveFlags.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found