[BUG] error TS2748: Cannot access ambient const enums when the '--isolatedModules' flag is provided.
See original GitHub issueEncountered 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:
- Created a year ago
- Reactions:2
- Comments:8 (6 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@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.
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 ofskipLibCheck
, 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.