#StackBounty: #angular #typescript #ionic3 #ionic-native #ionic-plugins TypeScript Cannot find name 'ClassName' even-though exp…

Bounty: 50

I have to use certain plugins in my Ionic 3 Application but it gives Cannot find name error. I imported

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

and on on declaring in constructor (public androidPermissions: AndroidPermissions), it gives an error ([ts] Cannot find name 'AndroidPermissions'.) .

On declaring the same plugin in app.module.ts and declaring in Provider, it gave the error

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

After reading forums, I imported the plugin with ngx.

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

Error got resolved, but on invoking it throws the error

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)

Similar error happened when using Network plugin and SMS plugin.

Also tried changing the target to es6 and jib to have es2016 in tsconfig.json but noting worked.
Below is my 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
  }
}


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.