Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 3 - All imports are unused warning (even though they are being used)

I am getting the following error when trying to run a prod build using the following

ionic cordova build browser --prod

Getting lot of warnings in the terminal like

FormBuilder is declared but never used

Even though in my code I am importing it and using it e.g.

import { Validators, FormGroup, FormBuilder } from '@angular/forms';

public form: FormGroup;

constructor(
    private formBuilder: FormBuilder
  ) {

setForm(){
    this.form = this.formBuilder.group({
      password: ['', Validators.required],
      password2: ['', Validators.required]
    });
  }

Has anyone had a similar problem? My guess it would be something to do with an npm package update.

Any advice would be great.

Thanks!

like image 630
user2085143 Avatar asked Jun 26 '17 12:06

user2085143


2 Answers

Ionic 3.3.0 (2017-05-24) removed the usage of legacy file 'src/declarations.d.ts' as mentioned in the changelog. Removing 'declarations.d.ts' from the src/ folder fixes the unused imports warning.

For more info check out the GitHub issue.

like image 101
Sebin Benjamin Avatar answered Nov 13 '22 14:11

Sebin Benjamin


I have the same issue and this is because tslint 5.0 changed how it checks unused variables.

You can suppress the warnings by changing the rules of the tslint.json file. I changed the "no-unused-variable" from true to false so it will look something like this:

{
  "rules": {
    "no-duplicate-variable": true,
    "no-unused-variable": [
      false
    ]
  },
  "rulesDirectory": [
    "node_modules/tslint-eslint-rules/dist/rules"
  ]
}

Of course this will suppress all warnings about unused variables but at anytime you can revert it to true to see if there are any other unused variables.

You can also add the following variable "noUnusedLocals": true to the tsconfig.json file:

{
  "compilerOptions": {
    "noUnusedLocals": true,
.
.
.
}

Just know that the "noUnusedLocals": true will throw errors instead of warnings though...

Hope this helps

like image 28
mcsavva Avatar answered Nov 13 '22 14:11

mcsavva