IONIC Serve : Runtime Error platform.toLowerCase is not a function


#1

I am using push notification in ionic 2 app with below code

import { Push, PushToken } from '@ionic/cloud-angular';
   @Component({...})
   export MyPage {     
    constructor(public platform: Platform, public menu: MenuController, public push: Push){
     this.initializeApp();
    }
    initializeApp() {
      this.platform.ready().then(() => {
       if (this.push) {
        this.push.register().then((t: PushToken) => {
          return this.push.saveToken(t);
        }).then((t: PushToken) => {
          console.log('Token saved:', t.token);
          window.localStorage.setItem("deviceToken", t.token);
        });

        this.push.rx.notification()
          .subscribe((msg) => {
            alert(msg.title + ': ' + msg.text);
            console.log('notification msg', msg);
          });
        }
      }
    }
}

when i run on device it works fine. but i do ionic serve it gives below error because of injection of Push in constructor

error_handler.js:53 TypeError: platform.toLowerCase is not a function
    at Insights.normalizeDevicePlatform (http://localhost:8100/build/main.js:70460:25)
    at Insights.markActive (http://localhost:8100/build/main.js:70450:33)
    at Insights.checkActivity (http://localhost:8100/build/main.js:70439:22)
    at http://localhost:8100/build/main.js:70415:27
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9723)
    at Object.onInvokeTask (http://localhost:8100/build/main.js:41825:37)
    at t.invokeTask (http://localhost:8100/build/polyfills.js:3:9659)
    at e.runTask (http://localhost:8100/build/polyfills.js:3:7083)
    at invoke (http://localhost:8100/build/polyfills.js:3:10836)
    at e.args.(anonymous function) (http://localhost:8100/build/polyfills.js:2:30123)
ErrorHandler.handleError @ error_handler.js:53

#2

Same here. Any help?


#3

I resolved it with below help got it from stackoverflow.

Check if you have the line “@ionic/cloud-angular”:"^ 0.9.0" in the package.json file, inside dependencies.

If so, switch it to ^0.9.1, save the file and run npm install in the project root folder. This should update @ionic/cloud-angular to 0.9.1 and its @ionic/cloud dependency to 0.15.1.

Then run ionic serve and it should work.