Uncaught (in promise): cordova_not_available in Ionic 2

前端 未结 8 1461
情书的邮戳
情书的邮戳 2020-12-13 12:33

When I\'m running my Ionic app with ionic serve -l command, get following error message:

Runtime Error

Unca

相关标签:
8条回答
  • 2020-12-13 13:13

    Cordova is only accessible when you run your app on a real device. When you test your app in the browser, it cannot access those native plugins.

    You can check if you are on a real device or a browser like that:

    if (this.platform.is('cordova')) {
      // You are on a device, cordova plugins are accessible
    } else {
      // Cordova not accessible, add mock data if necessary
    }
    

    This will only help you test the parts of your app that don't rely on cordova plugins. To really test your app, you need to run it on a device or in the emulator.

    0 讨论(0)
  • 2020-12-13 13:24

    Maybe something has changed since then, but Ionic now supports the "browser" as a platform ( vs simply browse ) - which makes the Cordova plugins available in the browser.

    To use it you add the platform ionic cordova platform add browser

    And then you run ionic cordova run browser vs ionic serve ( ionic run browser - just like ionic cordova run android or ionic cordova run ios )

    0 讨论(0)
提交回复
热议问题