2
votes

Trying to use the

cordova-sms-plugin

to add sms functionality in to the app. I have done the installation as mentioned in the docs -> https://ionicframework.com/docs/native/sms/

I add the line

import { SMS } from '@ionic-native/sms';

But when I add

public sms: SMS

in to the constructor arguments it throws in the below error in the JS console and the page stops working.

core.js:12501 ERROR Error: Uncaught (in promise): TypeError: Object(...) is not a function TypeError: Object(...) is not a function at index.js:93 at Module../node_modules/@ionic-native/sms/index.js (index.js:142) at webpack_require (bootstrap:83) at Module../src/app/pages/sendtext/sendtext.page.ts (pages-sendtext-sendtext-module.js:92) at webpack_require (bootstrap:83) at Module../src/app/pages/sendtext/sendtext.module.ts (pages-sendtext-sendtext-module.js:18) at webpack_require (bootstrap:83) at $_lazy_route_resource lazy namespace object:32 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invoke (zone.js:388) at Object.onInvoke (core.js:14060) at resolvePromise (zone.js:814) at resolvePromise (zone.js:771) at zone.js:873 at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:421) at Object.onInvokeTask (core.js:14051) at ZoneDelegate.push../node_modules/zone.js/dist/zone.js.ZoneDelegate.invokeTask (zone.js:420) at Zone.push../node_modules/zone.js/dist/zone.js.Zone.runTask (zone.js:188) at drainMicroTaskQueue (zone.js:595)

This is just a basic ionic installation with the only plugin added being the SMS plugin. Any help is appreciated.

Below is my dependencies section in the package.json file.

"dependencies": { "@angular/common": "~7.0.0", "@angular/core": "~7.0.0", "@angular/forms": "~7.0.0", "@angular/http": "~7.0.0", "@angular/platform-browser": "~7.0.0", "@angular/platform-browser-dynamic": "~7.0.0", "@angular/router": "~7.0.0", "@ionic-native/core": "5.0.0-beta.21", "@ionic-native/sms": "^4.18.0", "@ionic-native/splash-screen": "5.0.0-beta.21", "@ionic-native/status-bar": "5.0.0-beta.21", "@ionic/angular": "4.0.0-beta.16", "cordova-android": "7.1.4", "cordova-ios": "4.5.5", "cordova-plugin-device": "^2.0.2", "cordova-plugin-ionic-keyboard": "^2.1.3", "cordova-plugin-ionic-webview": "^2.2.5", "cordova-plugin-splashscreen": "^5.0.2", "cordova-plugin-statusbar": "^2.4.2", "cordova-plugin-whitelist": "^1.3.3", "cordova-sms-plugin": "0.1.13", "core-js": "^2.5.4", "rxjs": "~6.3.3", "zone.js": "~0.8.26" },

3
i hope you added this module in app.Module.R. Viral
Added the line import { SMS } from '@ionic-native/sms'; in app.module. Did not add it to any providers or anything.Ela Buwa

3 Answers

2
votes

Add module somethig like...

import { SMS} from '@ionic-native/sms';
@NgModule({
  providers: [
   SMS
  ]
})
1
votes

Okay so I was facing this same issue In my package.json I just changed sms plugin version and write it same as ionic-native/core which then execute command npm install and when i again serve my project it solved my issue

"@ionic-native/core": "^5.0.0",
"@ionic-native/sms": "^5.0.0",

Also in your module

import { SMS} from '@ionic-native/sms/ngx';
@NgModule({
  providers: [
   SMS
  ]
})
0
votes

Try Adding this

npm i rxjs@6 rxjs-compat@6 promise-polyfill --save