ionic cordova build 显示 lint 警告

Posted

技术标签:

【中文标题】ionic cordova build 显示 lint 警告【英文标题】:ionic cordova build is showing lint warnings 【发布时间】:2018-06-08 10:58:39 【问题描述】:

我正在尝试使用 IONIC 构建 APK 文件。在我尝试使用此命令构建 APK 之前,我正在关注所有教程并且一切正常:

$ ionic cordova build --release android

并告诉我这个错误:

 $ ionic cordova build --release android
    Running app-scripts build: --platform android --target cordova
    [22:57:28]  build dev started ...
    [22:57:28]  clean started ...
    [22:57:28]  clean finished in 9 ms
    [22:57:28]  copy started ...
    [22:57:30]  deeplinks started ...
    [22:57:31]  deeplinks finished in 416 ms
    [22:57:31]  transpile started ...
    [22:57:38]  transpile finished in 7.50 s
    [22:57:38]  preprocess started ...
    [22:57:38]  preprocess finished in less than 1 ms
    [22:57:38]  webpack started ...
    [22:57:40]  copy finished in 11.79 s
    [22:57:57]  webpack finished in 18.34 s
    [22:57:57]  sass started ...
    [22:57:59]  sass finished in 2.21 s
    [22:57:59]  postprocess started ...
    [22:57:59]  postprocess finished in 17 ms
    [22:57:59]  lint started ...
    [22:57:59]  build dev finished in 30.98 s
    > cordova build android --release

You have been opted out of telemetry. To change this, run: cordova telemetry on.
Android Studio project detected

(node:7784) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): TypeError: Cannot read property 'variables' of undefined
(node:7784) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

[22:58:05]  tslint: ...der (8)/App Source Code/App Source Code/src/providers/shared-data/shared-data.ts, line: 71
            Property 'push' is declared but never used.

      L70:  public events: Events,
      L71:  private push: Push,
      L72:  public platform: Platform,

[22:58:05]  tslint: ...der (8)/App Source Code/App Source Code/src/providers/shared-data/shared-data.ts, line: 8
            'PushObject' is declared but never used.

       L7:  import  LoadingProvider  from '../loading/loading';
       L8:  import  Push, PushObject, PushOptions  from '@ionic-native/push';
       L9:  import  Device  from '@ionic-native/device';

[22:58:05]  tslint: ...der (8)/App Source Code/App Source Code/src/providers/shared-data/shared-data.ts, line: 8
            'PushOptions' is declared but never used.

       L7:  import  LoadingProvider  from '../loading/loading';
       L8:  import  Push, PushObject, PushOptions  from '@ionic-native/push';
       L9:  import  Device  from '@ionic-native/device';

[22:58:05]  tslint: ...der (8)/App Source Code/App Source Code/src/providers/shared-data/shared-data.ts, line: 10
            All imports are unused.

       L9:  import  Device  from '@ionic-native/device';
      L10:  import  Facebook  from '@ionic-native/facebook';
      L11:  import  FCM  from '@ionic-native/fcm';

[22:58:05]  tslint: ...zm/Desktop/New folder (8)/App Source Code/App Source Code/src/pages/cart/cart.ts, line: 44
            Property 'storage' is declared but never used.

      L43:  public toast: Toast,
      L44:  private storage: Storage,
      L45:  public events: Events,

[22:58:05]  tslint: ...op/New folder (8)/App Source Code/App Source Code/src/pages/products/products.ts, line: 8
            All imports are unused.

       L7:  import  TranslateService  from '@ngx-translate/core';
       L8:  import  share  from 'rxjs/operator/share';
       L9:  import  CartPage  from '../cart/cart';

[22:58:05]  lint finished in 6.59 s

【问题讨论】:

【参考方案1】:

构建应用程序与提供应用程序不同。它更具限制性,因为您的应用程序需要尊重您所针对的平台的规范。 所以你必须纠正你在日志中看到的错误(比如删除一些你没有使用的变量或导入:

   `import  Device  from '@ionic-native/device';` 

编辑: 你有未使用的进口。虽然这不是一个错误,但这是一个错误。因此,在构建您的应用程序时,您不应该这样做。 你还有一些未使用的私有变量所以请删除它们。 只需阅读日志,您就会知道错误的位置以及要删除的内容。

【讨论】:

你是什么意思:所以你要么必须纠正你在日志中看到的错误(比如删除一些变量或你不使用的导入 - 我给你写代码如何纠正错误?? 当我删除此代码时显示错误您已选择退出遥测。要更改这一点,请运行:cordova telemetry on。检测到Android Studio项目(节点:9804)UnhandledPromiseRejectionWarning:未处理的承诺拒绝(拒绝ID:1):TypeError:无法读取未定义的属性“变量”(节点:9804)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。 [01:23:06] lint 在 69.58 秒内完成 是的,我刚刚注意到了。在您的代码中的某处,您有一个未定义的对象,并且您正在尝试访问该未定义对象的变量。我在这里帮不了你,你需要再次研究你的代码。这就是强烈建议对中/大型应用程序进行测试的原因。

以上是关于ionic cordova build 显示 lint 警告的主要内容,如果未能解决你的问题,请参考以下文章

ionic cordova build 成功,ionic cordova build --prod 报错

Ionic V4 - Build Prod “找不到 cordova.js 脚本标签。插件加载可能失败。”

ionic运行ionic build android出错

ionic cordova build android 报错 解决

Ionic Cordova Build Android 期间面临错误

ionic cordova build android - 失败