Cannot read property 'uuid' of undefined

When using the below Messaging code in Cordova/Ionic project, I get the error as sgiven.


Code causing the issue is:

var data = {
                deviceToken: null, //This value will set in callback
                deviceId   : device.uuid, // THIS ONE
                os         : device.platform,
                osVersion  : device.version


Cannot read property 'uuid' of undefined

Here’s where the error comes from:

I believe this plugin must be installed in order for the device registration code to work:

Thanks for response. This helps.

I have the device plugin installed via the Cordova CLI. I will check if I have to call the device registration inside the deviceready event to use the device object.

Thanks agian.