How to get rid of the warning .ts file is part of the TypeScript compilation but it's unused

后端 未结 16 1011
天命终不由人
天命终不由人 2020-12-30 18:20

I Just updated angular to latest 9.0.0-next.4. I am not using routing but suddenly after updating I keep seeing this warning. How Do I remove this warning

相关标签:
16条回答
  • 2020-12-30 18:59

    Updated to Angular 9 today and got warnings. My solution was add this "files" array without the "src" in the path. Just added:

     "files": [
        "main.ts",
        "polyfills.ts"
      ],
    

    My full tsconfig.app.json file is:

    {
      "extends": "../tsconfig.json",
      "compilerOptions": {
        "outDir": "../out-tsc/app",
        "module": "es2015",
        "types": ["node"]
      },
      "files": [
        "main.ts",
        "polyfills.ts"
      ],
      "exclude": [
        "src/test.ts",
        "**/*.spec.ts"
      ]
    }
    
    0 讨论(0)
  • Just add the zone-flags.ts as well and remove any includes.

     "files": [
        "src/main.ts",
        "src/polyfills.ts",
        "src/zone-flags.ts"
      ]
    
    0 讨论(0)
  • 2020-12-30 19:02

    For me, the problem was that I was using:

    loadChildren: () => import('./components/admin/_admin.module').then(m => m.AdminModule)
    

    in my routes.ts file but wasn't importing module. So if I just put

    import { AdminModule } from './components/admin/_admin.module';
    

    it solves it.

    0 讨论(0)
  • 2020-12-30 19:03

    This may seem obvious, BUT you will see this warning for any file that you add but is not yet referenced/imported into another file. This will become obvious when you attempt to edit one of the files subject to the warning, and Ivy does not automatically recompile after editing the file. Once you import the module into a dependent file and start using it, the warnings go away.

    The answers above may be relevant to some, but what I just described in this post was the root cause of my warnings. Note, I do not have an include or files array in my tsconfig.json or tsconfig.app.json and the warnings went away as soon as I actually referenced the files elsewhere in my project.

    0 讨论(0)
提交回复
热议问题