When working on my Ionic 3 Application, I encountered an error stating "Cannot find name" when trying to use certain plugins. I initially imported the plugin like this:
import { AndroidPermissions } from '@ionic-native/android-permissions';
and then declared it in the constructor like this:
(public androidPermissions: AndroidPermissions)
, which resulted in the error ([ts] Cannot find name 'AndroidPermissions'.)
.
Trying to declare the plugin in app.module.ts and as a Provider led to the following error:
[ts]
Type 'AndroidPermissionsOriginal' is not assignable to type 'Provider'.
Type 'AndroidPermissionsOriginal' is missing the properties 'provide' and 'useFactory' [2322]
After further research, I found that importing the plugin with ngx solved the initial error:
import { AndroidPermissions } from '@ionic-native/android-permissions/ngx'
However, upon invoking it, a new error was thrown:
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)
... //(more stack trace)
A similar issue arose when using the Network plugin and SMS plugin.
I also attempted to change the target to es6 and jib to include es2016 in tsconfig.json but none of these solutions worked for me. Below is a snippet of my tsconfig.json file:
{
"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
}
}