Ionic 3.5.3 - tslint: inaccurate and frequent lint warnings of 'All imports are unused.'


#1

I’ve just updated to Ionic 3.5.3, and I’m noticing a pattern of frequent “All imports are unused” lint warnings --when, in fact the imports are used.

Example warning:

[17:00:26]  tslint: ...example.ts, line: 2
            All imports are unused.

       L1:  import { Injectable } from '@angular/core';
       L2:  import { Http } from '@angular/http';
       L3:  import 'rxjs/add/operator/map';

referring to the following code:

import { Injectable } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/add/operator/map';

import { ConstProvider } from '../providers/example';

@Injectable()
export class Example{
  public data: any;

  constructor( public http: Http, private constProvider: ConstProvider ) {}

today() {
  if (this.data) {
    return Promise.resolve(this.data);
  }

  return new Promise(resolve => {
    this.http.get(this.constProvider.apiURL + '/example')
      .map(res => res.json())
      .subscribe(data => {
        this.data = data;
        resolve(this.data);
      });
    });
  }
}

This code works fine. Just get lint warnings on ionic serve, ionic cordova build, ionic upload

global packages:

@ionic/cli-utils : 1.5.0
Cordova CLI      : 7.0.1
Ionic CLI        : 3.5.0

local packages:

@ionic/app-scripts              : 2.0.2
@ionic/cli-plugin-cordova       : 1.4.1
@ionic/cli-plugin-ionic-angular : 1.3.2
Cordova Platforms               : android 6.1.2 browser 4.1.0 ios 4.3.1
Ionic Framework                 : ionic-angular 3.5.3

System:

Node       : v6.11.1
OS         : Windows 10
Xcode      : not installed
ios-deploy : not installed
ios-sim    : not installed
npm        : 3.10.10

#2

There’s an app-scripts issue on Github about this, but it’s never happened to me. So I suspect it is due to an unclean installation that is easy to create if you upgrade from a previous version. I’d suggest you (1) completely delete previous Ionic installation and cache and reinstall, then (2) check the Github issues if that doesn’t solve the problem.


#3

Thanks for the Github pointer and the suggestions. If by “delete previous Ionic installation and cache and reinstall” you mean delete node_modules and npm cache clean and npm install, done, done and done. Rinse and repeat. :smile:

I would welcome any other thoughts or suggestions.

Bogus lint warnings are not critical …just very annoying.


#4

I have the same problem, for now I don’t know a solution either.


#5

As per this thread, simply delete the src/declarations.d.ts file, apparently, it’s not even being created with new Ionic instances. Thread Link


#6

Thank you! Worked like a charm!