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

后端 未结 3 743
鱼传尺愫
鱼传尺愫 2021-02-15 16:55

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

ionic cordova build browser --prod

Getting lot

3条回答
  •  挽巷
    挽巷 (楼主)
    2021-02-15 17:26

    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

提交回复
热议问题