打字稿找不到名称“className”偶虽然出口离子3

问题描述 投票:5回答:2

我在我的离子3应用程序使用某些插件,但它给找不到名称错误。我进口

import { AndroidPermissions } from '@ionic-native/android-permissions';

并在构造函数中(public androidPermissions: AndroidPermissions)宣布,它给出了一个错误([ts] Cannot find name 'AndroidPermissions'.)

在声明中app.module.ts相同的插件,并在供应商宣布,它给了错误

[ts]
Type 'AndroidPermissionsOriginal' is not assignable to type 'Provider'.
Type 'AndroidPermissionsOriginal' is missing the following properties from type 'FactoryProvider': provide, useFactory [2322]

阅读论坛后,我用进口的NGX插件。

import { AndroidPermissions } from '@ionic-native/android-permissions/ngx'

错误得到了解决,但在调用它引发错误

Uncaught (in promise): TypeError: Object(...) is not a function
TypeError: Object(...) is not a function
    at AndroidPermissions.requestPermissions (http://192.168.0.13:8100/build/vendor.js:69796:154)
    at http://192.168.0.13:8100/build/main.js:138:32
    at t.invoke (http://192.168.0.13:8100/build/polyfills.js:3:14976)
    at Object.onInvoke (http://192.168.0.13:8100/build/vendor.js:5134:33)
    at t.invoke (http://192.168.0.13:8100/build/polyfills.js:3:14916)
    at r.run (http://192.168.0.13:8100/build/polyfills.js:3:10143)
    at http://192.168.0.13:8100/build/polyfills.js:3:20242
    at t.invokeTask (http://192.168.0.13:8100/build/polyfills.js:3:15660)
    at Object.onInvokeTask (http://192.168.0.13:8100/build/vendor.js:5125:33)
    at t.invokeTask (http://192.168.0.13:8100/build/polyfills.js:3:15581)

使用Network pluginSMS plugin时发生类似的错误。

也试着改变目标,以ES6和悬臂有在tsconfig.json es2016但注意到工作。下面是我tsconfig.json

{
  "compilerOptions": {
    "allowSyntheticDefaultImports": true,
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "lib": [
      "dom",
      "es2015"
    ],
    "module": "es2015",
    "moduleResolution": "node",
    "sourceMap": true,
    "target": "es5"
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules",
    "src/**/*.spec.ts",
    "src/**/__tests__/*.ts"
  ],
  "compileOnSave": false,
  "atom": {
    "rewriteTsconfig": false
  }
}
angular typescript ionic3 ionic-native ionic-plugins
2个回答
0
投票

如果您使用的离子版本3(不是最新的),请参考下面提及的文档https://ionicframework.com/docs/v3/native/android-permissions/

首先删除 离子科尔多瓦插件删除科尔多瓦-插件-机器人的权限

再有它添加

$离子科尔多瓦插件添加科尔多瓦 - 插件,Android的权限

$ NPM安装--save @离子本地/ Android的权限@ 4


0
投票

试试这些命令 - 删除包lock.json

ionic cordova platform remove android npm install ionic cordova platform add [email protected] ionic cordova plugin add cordova-plugin-android-permissions npm install --save @ionic-native/android-permissions@4

© www.soinside.com 2019 - 2024. All rights reserved.