ApplicationInsights-JS: Typescript 2.9, ai.module.d.t.s is not a module

When trying to use it with typescript I am seeing ai.module.d.ts not a module error when using both. @types/applicationinsights-js and ai.module.d.ts If I do not install @types/applicationinsights-js ts tells me to install it saying type definitions not found If I install @types/applicationinsights-js and delete ai.module.d.ts everything works.

I was wondering why that happens and why there are multiple type definitions?

Thank you

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 8
  • Comments: 41 (15 by maintainers)

Most upvoted comments

This GitHub issue has been created to track the issue, so that the applicationinsights-js team is aware there is a problem and to notify users when the issue is fixed. We have a workaround, there is no urgent need to fix the problem but there is a desire from the community to see it fixed.

Please keep any further discussion on topic.

Folks, I published a new NPM package with a beta tag. The package simply does not include ai.module.d.ts. Please give it a try and let me know if that works for you without any hacks.

npm install applicationinsights-js@beta

Same here - we use AI.JS in our core project, therefore all nightly builds failed. We used band-aid fix:

declare module "applicationinsights-js"; in typings.d.ts.

“downgrade from latest version of another package because nobody will fix this package”. good advice.

We’re receiving the same error message when trying to upgrade from TypeScript 2.8.4 to 2.9.1 (in 2.8.4 it works fine). We’re importing Application Insights like so:

import { AppInsights } from 'applicationinsights-js';

and the exact error message we’re seeing is:

TS2306: File 'C:/blablabla/node_modules/applicationinsights-js/bundle/ai.module.d.ts' is not a module.

package.json has version "applicationinsights-js": "1.0.17". The module style in tsconfig.json is set to commonjs.

We know it works for 2.8.X. The issue is that the included typings break our builds in 2.9.X.

Thank you for letting us know that we have the option to downgrade.

Can the applicationinsights-js developers take a look at this for those of us who want to continue using TS 2.9.X? This is the only module I’m experiencing this issue with.

FYI for all. We decided to stop generating the ai.module.d.ts, and let developers depend on the @types package. I am making the fix this week. Thanks

Deployment is complete. latest applicationinsights-js package should contain the fix. Thanks.

@ayrtonmassey change your dev dependency to:

"devDependencies": { "typescript": ">=2.6.2 <2.8.5", ... }

Then do an NPM install again and try.

Here is a workaround for 2.9. Make sure you have a custom typings file, for example in your tsconfig.json

{
  ...
  "compilerOptions": {
    ...
    "typeRoots": ["@types", ...]
    ...
  }
}

Then in your <project>/@types/custom.d.ts:

declare module 'applicationinsights-js' {
    const AppInsights: Microsoft.ApplicationInsights.IAppInsights;
}

And voila, the import works and is typed: import { AppInsights } from 'applicationinsights-js';

Updated to "applicationinsights-js": "1.0.19", "@types/applicationinsights-js": "1.0.6". Works perfectly, thanks!

Hi @praneetloke. We deployed to our pre-production on Monday, and today we’re ready to deploy to real production. I’ll update the thread as soon as we are deployed.

"applicationinsights-js": "^1.0.19-beta.1", and "@types/applicationinsights-js": "^1.0.5" worked for us! thanks!

I’m having the same issue after upgrading my Angular (CLI) project to typescript@2.9.2. node_modules/applicationinsights-js/bundle/ai.module.d.ts' is not a module.

 - applicationinsights-js@1.0.18
 - @types/applicationinsights-js@1.0.5

Based on your suggestions, I’ve tried the following :

One of the solutions proposed for this involve not generating the ai.module.d.ts. I am curious does anyone take a dependency on this file by using the reference tag as such? ///// <reference path="./node_modules/applicationinsights-js/bundle/ai.module.d.ts" />

@engineersamuel I tried with the following:

package.json

...
"dependencies": {
    "applicationinsights-js": "1.0.18",
    ...
},
"devDependencies": {
    "typescript": "2.9.1",
    ...
}
...

tsconfig.json

...
"typeRoots": [
    "./src/@types", 
    "./node_modules/@types"
],
...

src/@​types/custom.d.ts

declare module 'applicationinsights-js' {
    const AppInsights: Microsoft.ApplicationInsights.IAppInsights;
}

i.e. without @types/applicationinsights-js, but it still didn’t work for me.

The solution I posted above (install @types/applicationinsights-js, use a postinstall hook to remove ai.module.d.ts) worked for me.

When I do not install @types/applicationinsights-js I get ai.module.d.ts is not a module during build and when hovered on the error in vscode it says:

Could not find a declaration file for module 'applicationInsights.js' ai.module.js implicitly has an 'any' type try npm install @types/applicationinsights-js

Additionally when both bundle/ai.module.d.ts and @types/applicationinsights-js is there/installed it does not build in recently updated typescript 2.9.0 .

However it does build fine in typescript 2.8.3 although not sure how these are related after I skimmed through the changelogs of typescript.