angulartypescriptimportangular18angular-compiler

How to get rid of "Imports array contains unused imports(-998113)"


Ever since I've upgraded my app to the latest version of Angular (18.2.0), I'm getting this warning message in many of the components:

Imports array contains unused imports(-998113)

Now, I understand the meaning of this and why it's showing up like that, and basically it's great that it exists, to let me know (although it doesn't say which import(s) are not used!). But nevertheless, I don't want it to appear, and without removing unused imports.

Is there a setting or a configuration that I can use to stop getting these warning message?


Solution

  • The warning about unused imports in standalone components was introduced in Angular 19 (you can find more details in the official blog post here: https://blog.angular.dev/meet-angular-v19-7b29dfd05b84).

    It seems that you've updated the "Angular Language Service" plugin in VS Code to version 19, but you haven't yet upgraded Angular itself in your package.json.

    As a result, you're seeing the warning in VS Code, but when you try to build or serve your app, you encounter the following error: TS-994005: Angular compiler option "extendedDiagnostics.checks" has an unknown check: "unusedStandaloneImports."

    To resolve this, you should update your Angular version to v19 in your package.json. This will allow the compiler to recognize the newly added extended diagnostics check for unused standalone imports. Once you've made this update, the TS-994005 error should disappear, and you can also suppress the check in your angularCompilerOptions as needed.