Tips for removing the notification that the .ts file is included in the TypeScript compilation but not actively used

After updating angular to the latest version 9.0.0-next.4, I am encountering a warning message even though I am not using routing in my project. How can I get rid of this warning?

A warning is being displayed in

src/war/angular/src/app/app-routing.module.ts
as part of the TypeScript compilation but it's unused. Make sure to add only entry points to the 'files' or 'include' properties in your tsconfig.

package.json

  "dependencies": {
"@angular/animations": "^9.0.0-next.4",
"@angular/cdk": "^8.1.4",
"@angular/common": "^9.0.0-next.4",
"@angular/compiler": "^9.0.0-next.4",
"@angular/core": "^9.0.0-next.4",
"@angular/forms": "^9.0.0-next.4",
"@angular/material": "^8.1.4",
... (remaining content unchanged)
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "^0.803.2",
    ... (remaining content unchanged)
  }

tsconfig.json

    {
  "compileOnSave": false,
  ... (remaining content unchanged)
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

Answer №1

The solution was to eliminate the line "src/**/*.ts" from the "include" section of tsconfig.app.json, and instead focus on keeping entry points in specific files like main.ts and polyfills.ts.

Answer №2

To successfully enable the functionality, I made sure to specify the files attribute within the configuration file named tsconfig.app.json. These specified files are referenced in relation to the location of the tsconfig.app.json file.

"files": [
    "app.js",
    "styles.scss"
  ]

Answer №3

Following an upgrade from Angular 8 to Angular 9, I encountered complaints about environment.*.ts files that were listed in angular.json for various builds. Despite not running ng update, which would typically update tsconfig.json with certain configurations, I manually updated tsconfig.json as a workaround.

    "files": [
        "src/main.ts",
        "src/polyfills.ts"
    ],
    "include": [
        "src/**/*.d.ts"
    ]

Fortunately, this resolved the warnings for me.

Update on May 27, 2020:

I discovered that the previously mentioned block of code is no longer necessary with Angular 9.1.x in Visual Studio Professional 2019. Keeping it could lead to errors in spec test codes complaining about missing modules, even though everything appears to be functioning correctly during testing and building.

Below is my current tsconfig.json configuration:

{
    "compileOnSave": false,
    "compilerOptions": {
        "baseUrl": "./",
        "outDir": "./dist/out-tsc",
        "sourceMap": true,
        "declaration": false,
        "module": "es2020",
        "moduleResolution": "node",
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "target": "es2015",
        "typeRoots": [
            "node_modules/@types"
        ],
        "lib": [
            "es2018",
            "dom"
        ],
        "skipLibCheck": true
    }
}

Remarks:

As a note, my development targets are Google Chrome and Safari. If you plan to target other browsers, adjustments may be necessary.

Answer №4

Have you encountered issues with @angular-builders/custom-webpack?

I suddenly started receiving unfamiliar messages in my Angular 10 project. Even after adjusting the includes, the problem persisted.

Fortunately, I stumbled upon https://github.com/angular/angular/pull/36211.

This issue seems similar to what was mentioned here but related to ngtypecheck.ts files (not entirely certain about their purpose!)

WARNING in /home/circleci/ng/aio/src/main.ngtypecheck.ts is part of the TypeScript compilation but it's unused. Add only entry points to the 'files' or 'include' properties in your tsconfig.

In my case, it appears to be connected to @angular-builders/custom-webpack.

There was recently an open discussion regarding this at https://github.com/just-jeb/angular-builders/issues/781. Kudos to for bringing attention to this.

My solution was updating to v10.0.1, which resolved the issue for me. However, I recommend checking the aforementioned thread for any new updates.

"@angular-builders/custom-webpack": "10.0.1"    // current version

Answer №5

It may be obvious to some, but it's worth noting that you will receive a warning for any file you add that is not yet referenced or imported into another file. The significance of this will become apparent when you try to edit one of the files mentioned in the warning, only to find that Ivy does not automatically recompile after the edit. Once you import the module into a dependent file and begin using it, the warnings will disappear.

While the answers provided by others may be helpful, the root cause of my warnings was exactly what I have described in this post. It's important to mention that I did not have an include or files array in my tsconfig.json or tsconfig.app.json files, and the warnings ceased once I actually referenced the files elsewhere in my project.

Answer №6

Just updated to the latest Angular 9 and encountered some warnings. I found a solution by adding an array called "files" in my tsconfig.app.json without including the "src" path:

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

Here is my complete tsconfig.app.json file after making the changes:

{
  "extends": "../tsconfig.json",
  "compilerOptions": {
    "outDir": "../out-tsc/app",
    "module": "es2015",
    "types": ["node"]
  },
  "files": [
    "main.ts",
    "polyfills.ts"
  ],
  "exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]
}

Answer №7

February 8th, 2020

Creating an Ionic 5+ Angular 9+ application.

Please take note: refer to the include section for more information.

tsconfig.app.json

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ],
  "exclude": [
    "src/**/*.spec.ts"
  ]
}

Answer №8

Include the zone-flags.ts file and ensure that no other files are included in the list.

"files": [
    "src/main.ts",
    "src/polyfills.ts",
    "src/zone-flags.ts"
  ]

Answer №9

tsconfig.app.json

 "exclude": [
    "src/**/*.spec.ts",
    "src/test.ts",
    "src/environments/environment.prod.ts"
  ]

This code snippet provides the solution to the problem.

Answer №10

Upon encountering the notifications in Angular 10, I found it rather unexpected considering that it was a recent application generated using the CLI without any modifications. The warnings surfaced during a production build for both test.ts and environments.prod.ts. One would assume that these files would be automatically excluded, but to my surprise, they were not.

The reality is that these files are unnecessary for TypeScript transpilation; there is no need to bundle and deliver the .js versions of them to the browser. Both test.ts and environments.prod.ts serve as tools for meeting build-time requirements in Angular applications. Therefore, they can be included in the exclude section of the tsconfig.app.json file or any relevant TypeScript configuration file within your app, as illustrated below:

"exclude": [
    "src/**/*.spec.ts",
    "src/test.ts",
    "src/environments/environment.prod.ts"
]

By incorporating these additions as mentioned above, the warning alerts will cease to appear.

Answer №11

To resolve the issue, consider removing the directory node_modules/.cli-ngcc that stores the Angular CLI cache data.

Answer №12

After trying out the previous proposed solutions, I found success.

Make sure to update your package.json file

"@angular-devkit/build-angular": "~0.1000.3" 

You can view all available versions here:

https://www.npmjs.com/package/@angular-devkit/build-angular?activeTab=versions

Check which version is compatible with your current angular/core version

For Angular 10, use version 0.1000.3 of @angular-devkit/build-angular

Answer №13

Arriving fashionably late.

Encountered an issue here

The file src/environments/environment.prod.ts is a part of TypeScript compilation process, but it seems to be unused.
To address this, I must include the configuration in my tsconfig.app.json file

To resolve this, I will add the following entries to my tsconfig.app.json file:

"files": ["src/main.ts", "src/polyfills.ts"],
"include": ["src/**/*.d.ts"],

Answer №14

When I made the switch to Angular 10, I encountered similar warnings. Upon running npm i, there were reports of version discrepancies for certain development dependencies. By updating these (npm i <package>@latest) and moving nodejs to version 12 (previously was on version 10), the warnings disappeared.

In my scenario, the following packages required updates:

  • @angular-devkit/build-angular
  • codelyzer

Answer №15

Interestingly, I found that the classes mentioned in the warning message were indeed being used in my situation. The issue, however, stemmed from the fact that when importing these classes, they had the extension ".js".

Consequently, this specific line triggered the warning "WARNING in src\app\user.service.ts is part of the TypeScript compilation but it's unused":

import { UserService } from './user.service.js';

The problem was easily resolved by simply removing the ".js" extension:

import { UserService } from './user.service';

Answer №16

After struggling with a persistent issue for months, my team and I finally identified the root cause of our problem: an overly broad configuration in our tsconfig.worker.json. Countless "part of the TypeScript compilation but it's unused" messages flooded our logs, with seemingly every ts file in the application being listed multiple times.

The original configuration looked like this:

"include": [
  "src/**/*.worker.ts"
]

To resolve the issue, we made a simple adjustment:

"files": [ ]   # no include or exclude block

It appears that our standard tsconfig.app.json's files entry points were sufficient for the TS compiler to transpile all the necessary *.worker.ts files based on main.ts and polyfills.ts references. The redundant references in tsconfig.webworker.ts seemed to be causing confusion, resulting in excessive warnings. It is possible that our webworker files (of which we have around 20) are needlessly importing unnecessary dependencies.

By implementing this tweak, we successfully eliminated the warning overload and significantly reduced our compilation time. What a relief!

Answer №17

After trying various approaches, I finally managed to find a solution for the issue at hand.

The challenge I faced involved upgrading an Angular 8.1 app to Angular 9.x while also utilizing Ionic.

To address this, ensure that you only have aot: true within the angular.json file.

In the src/polyfills.ts file, remember to import './zone-flags.ts' without the .ts extension.

For more guidance on upgrading from Ionic 4 to Ionic 5 with Angular, refer to this resource: https://medium.com/@grantbrits/upgrade-ionic-4-to-ionic-5-angular-76514079fb2aenter image description here

Answer №18

Take a look at your primary tsconfig.app.json configuration file.

https://i.stack.imgur.com/Vy9OE.png

Check if you have the following setup within it:

{
  "extends": "./tsconfig.json",
  "compilerOptions": {
    "outDir": "./out-tsc/app",
    "types": []
  },
  "files": [
    "src/main.ts",
    "src/polyfills.ts"
  ],
  "include": [
    "src/**/*.d.ts"
  ]
}

It's likely that the issue stems from these specific lines.

Make sure to only include entry points in the files or include properties of your tsconfig.

If these lines exist in your tsconfig.app.json, consider removing them. This is likely causing the error :)

"exclude": [
    "src/test.ts",
    "**/*.spec.ts"
  ]

I hope this information can be beneficial to someone out there.

Thank you.

Answer №19

After upgrading my Angular 9 application to Angular 10, I encountered a similar problem. Fortunately, the issue was resolved by updating angular-devkit.

Answer №20

For me, the simpler solution was to remove the unnecessary files:

"exclude": ["data.ts", "**/*.backup.ts","samples/test.*.ts"]

Answer №21

In the situation I encountered, my tsconfig.json file was lacking the exclude directive for spec files. By adding the specific exclude rule in my tsconfig file as shown below, I was able to resolve the problem.

"exclude": [
"**/*.spec.ts",
"./node_modules/*"
],
 "files": [
"src/main.ts",
"src/polyfills.ts"
]

Answer №22

Essentially, the issue arises during runtime when the compiler verifies whether certain files are being imported or used in any way. If they are not, warnings are generated. If these warnings specifically pertain to environment.ts files, you have the option to exclude them in tsconfig.app.json like mentioned in the comments. However, if the warnings relate to components that are not being utilized anywhere, it is crucial to investigate why and determine if they can be safely removed.

Answer №23

I faced a similar issue as well. The problem stemmed from my angular.json file pointing to the incorrect tsConfig file. Instead of targeting tsconfig.app.json, it was referencing tsconfig.json.

To resolve this in angular.json:

"build": {
    "options": {
        "polyfills": "src/polyfills.ts",
        "tsConfig": "src/tsconfig.app.json"
    }
}

In tsconfig.app.json, I made sure to extend tsconfig.json and added the necessary 'files' and 'include' arrays to address the issue effectively.

Answer №24

Initially, my issue was caused by using:

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

within my routes.ts file without importing the module. The solution was simply to add

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

and that resolved the problem.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Angular Universal: Troubleshooting an Unrendered Route

Struggling for hours to make my site Universal and support Server Side Rendering, I came across the issue where the base route '' is not being rendered by the server. Surprisingly, all other routes are functioning properly when directly called fr ...

The pipe operator in RxJS is never executed in the Observable fork

I am attempting to execute and retrieve values from an array of observables (each obtained from literalsService) using a pipe. Below is the code snippet: translateLiterals() { const literalsToTranslate: string[] = [ 'certificate_title', ...

How to eliminate the button from Google Maps API using JavaScript

I am trying to implement a specific functionality on my map. When the user drags the map, I want a button named 'Search in this area' to appear. Once the user clicks on the button, it should disappear so that the search can't be performed ag ...

How come TypeScript does not generate an error when attempting to import a default export that does not exist?

As I work on converting my code from non-TypeScript CommonJS files to TypeScript ES6 modules, I encountered an issue with the import statements. Specifically, I needed to use import * as x instead of import x: The original snippet looked like this: const ...

Angular 2 TypeScript: The concat() function operates as mutable within the framework

When I declare an array on an @Injectable provider, my intention is to use it across different components. normeList: any[] = [ { name: 'choice 1', type:'false' }, { name: 'choice 2', typ ...

Ways to store data in the localStorage directly from a server

I'm facing an issue - how can I store data in localStorage that was received from the server? Should I use localStorage.setItem for this purpose? And how do I handle storing an array in localStorage? Or am I missing something here? import { HttpCli ...

How to access properties of objects within an array in Angular 4

Is there a method to call only the $values from each rate record in my array that I want to read? This is what I have done to access this array: async ngOnInit() { this.product$ = await this.reviewService.getReview(this.product.$key); this.key = ...

Guide on achieving horizontal scrolling in Ionic 3

Check out this image I have a list of 10 names in an ion-scroll, but they are appearing on separate lines like paragraphs. Below is my HTML code: <ion-scroll scrollX="true" style="width:100vw; height:50px" > <ion-row class="headerChip"& ...

Can you please explain the process of implementing server-side rendering with React?

During my work, I utilized Node's express for sever side rendering with React. However, an unexpected error occurred as shown below. ^ SyntaxError: Unexpected token '<' This particular error popped up unexpectedly. I reached ou ...

Unable to access the `isDragging` property in TypeScript when using the `useDrag` method from react-d

As a newcomer to utilizing react in combination with typescript, I am currently working on implementing a drag and drop feature using the react-dnd package along with typescript. I came across this helpful blog that has guided me through the process of dra ...

Changing Image to Different File Type Using Angular

In my Angular Typescript project, I am currently working on modifying a method that uploads an image using the input element of type file. However, I no longer have an input element and instead have the image file stored in the assets folder of the project ...

Steps to prevent uib-timepicker from automatically adjusting time based on the Browser Timezone

Currently in my database, timestamps are stored in UTC format. On the frontend, I am implementing uib-timepicker for time editing and updating purposes. However, I do not want uib-timepicker to automatically convert the time from the server's timezone ...

ERROR: There was a problem with the NgbTabset class at line 12 in the inline template. This issue occurred because the 'templateRef' property could not be read as it was undefined

I am utilizing ng-bootstrap instead of ui-bootstrap in angular2 for my project. This is the HTML code I am using: <div class="row" style="height: 100%;"> <div class="col-12"> <div class="container" id="contentMain"> <div ...

Trouble arises with connect-mongo, passport, and passport-local-mongoose as session fails to persist

Seeking assistance with saving session and incorporating functionality like req.isAuthenticated(), req.user, etc., but unable to make it work. Session does not persist and seems to be malfunctioning for unknown reasons. app.ts https://pastebin.com/yGvUZh ...

What is the reason that control flow analysis does not support the never type?

Here is the scenario I'm dealing with (utilizing strictNullChecks): function neverReturns(): never { throw new Error(); } const maybeString: string | null = Math.random() > 0.5 ? "hi" : null; if (!maybeString) { neverReturns(); // th ...

Synchronizing Form Data in Angular 5: Pass and Populate Dropdowns between Components

I have developed a unique form (material dialog modal) that allows users to create an account. When the user clicks on the Register button, their created account should appear in a dropdown menu without redirecting or reloading the current page. I am facin ...

Update current properties of objects

I'm feeling like I'm going crazy and could really use some assistance. My predicament involves a function that looks like this: private generateTimeObject(firstObject: someInterface, secondObject?: someInterface) { let firstTime; let secondTi ...

The "void" type cannot be assigned to the type "ObservableInput<{}>"

I recently encountered this issue after updating to TS 2.2.2, and I suspect that is the root cause... While the code still functions properly, I am now seeing this error. I attempted various solutions such as returning an empty observable, catching the re- ...

What measures can I take to ensure TypeScript transpiles prototype methods effectively?

Having some issues defining methods on a TypeScript class and then accessing them. Even though the methods are defined, it's giving an error that they don't exist. TypeScript: export class ColumnHeader extends JSONObject { // ... i ...

The npm script for running Protractor is encountering an error

Currently, I am facing an issue while trying to execute the conf.js file using an npm script. The conf.js file is generated within the JSFilesRepo/config folder after running the tsc command as I am utilizing TypeScript in conjunction with protractor-jasmi ...