4

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" },

2
  • i hope you added this module in app.Module. Commented Dec 5, 2018 at 5:38
  • Added the line import { SMS } from '@ionic-native/sms'; in app.module. Did not add it to any providers or anything. Commented Dec 5, 2018 at 5:40

3 Answers 3

4

Add module somethig like...

import { SMS} from '@ionic-native/sms';
@NgModule({
  providers: [
   SMS
  ]
})
Sign up to request clarification or add additional context in comments.

8 Comments

Still get an error saying index.js:93 Uncaught TypeError: Object(...) is not a function
try with rebuild development environment with ionic serve -l
I have removed the plugin references from every page. Only have the import in the app.module page and have SMS in the providers list. I still get the same error. But the app's first page doesn't load at all.
please make sure you following these steps, 1. add sms pligin with ionic cordova plugin add cordova-sms-plugin and npm install --save @ionic-native/sms 2. Add sms in app.module which i mention in above answer 3. then related page you need to add in constructor like private sms: SMS 4. now with this.sms you can use all methods of sms plugin
Did a fresh install. the npm install command gave this warning. npm WARN @ionic-native/[email protected] requires a peer of @ionic-native/core@^4.11.0 but none is installed. You must install peer dependencies yourself. However, "@ionic-native/core": "5.0.0-beta.21", is in the package.json file.
|
2

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
  ]
})

Comments

0

Try Adding this

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.