ionic-framework: [Ionic v4.0.0-beta.12] Cordova is not available

Bug Report

Ionic Info

Ionic:

   ionic (Ionic CLI)             : 4.2.1 (/usr/lib/node_modules/ionic)
   Ionic Framework               : @ionic/angular 4.0.0-beta.12
   @angular-devkit/build-angular : 0.7.5
   @angular-devkit/schematics    : 0.7.5
   @angular/cli                  : 6.1.5
   @ionic/angular-toolkit        : 1.0.0

Cordova:

   cordova (Cordova CLI) : 8.0.0
   Cordova Platforms     : android 7.0.0
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 2.2.0, (and 5 other plugins)

System:

   Android SDK Tools : 26.1.1 (/home/enzo/Android/Sdk)
   NodeJS            : v8.11.4 (/usr/bin/node)
   npm               : 5.6.0
   OS                : Linux 4.15

Describe the Bug Cordova is not loaded on a fresh-installation.

Steps to Reproduce Steps to reproduce the behavior:

  1. Start a project: ionic start ionic4-test --type=angular
  2. Add Android as platform
  3. Add some @ionic-native plugin (like google-maps)
  4. Run ionic cordova run android -l and you will see warnings/errors since cordova is not available, for example: Native: tried calling StatusBar.styleDefault, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator Native: tried calling SplashScreen.hide, but Cordova is not available. Make sure to include cordova.js or run in a device/simulator Error: Uncaught (in promise): TypeError: Cannot read property 'BaseClass' of null TypeError: Cannot read property 'BaseClass' of null (error with @ionic-native/google-maps)

Related Code GitHub.

Expected Behavior Cordova has to be loaded in the app.

Additional Context In ionic 3 we had a script with cordova.js. Now, in ionic4, I don’t see that and don’t know how it should be included. But even in an fresh-installation app, it doesn’t work.

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 7
  • Comments: 20 (3 by maintainers)

Most upvoted comments

Had this problem recently, and can confirm it only occurs with live reload enabled.

Solution: downgrade @ionic/ng-toolkit to 1.0.8 as opposed to latest 1.1.0.

Side note: Ionic seems to be switching to a merged package of ng-toolkit & schematics-angular called “angular-toolkit” which also contains the same problem with live reload, thus fresh installs also contain this problem since defaults to new merged package. So for now with fresh installs, uninstall @ionic/angular-toolkit and install @ionic/ng-toolkit & @ionic/schematics-angular (also need to switch angular.json to version that uses the two packages as opposed to the new merged one).

Thanks for your response! Could you open a feature request for it? That would be great 😃

UPDATE: You shouldn’t use livereload because this can to be a problem

For me it looks like an issue in your cordova creating process. I am creating several apps with Ionic and Cordova and do not have this issue.

  1. Start a project: ionic start ionic4-test --type=angular
  2. Add Android platform: ionic cordova platform add android
  3. Run the android: ionic cordova run android

Keep in mind that in angular.json the correct builder have to be added from ionic

        "ionic-cordova-build": {
          "builder": "@ionic/angular-toolkit:cordova-build",
          "options": {
            "browserTarget": "app:build"
          },
          "configurations": {
            "production": {
              "browserTarget": "app:build:production"
            }
          }
        },
        "ionic-cordova-serve": {
          "builder": "@ionic/angular-toolkit:cordova-serve",
          "options": {
            "cordovaBuildTarget": "app:ionic-cordova-build",
            "devServerTarget": "app:serve"
          },
          "configurations": {
            "production": {
              "cordovaBuildTarget": "app:ionic-cordova-build:production",
              "devServerTarget": "app:serve:production"
            }
          }
        }

I can confirm @JupiterSymphony workaround is working with fresh project.

ionic serve -c still doesn’t have Cordova working on device

I have the same problem, how to fix this?

Hi!, finally solved downgrading @ionic/ng-toolkit to 1.0.8

thanks for @JupiterSymphony

Regards!

Hi @tebantebanteban . Sorry but that is the output of ionic info command. I mean the content of the package.json. I’d like to see what dependencies you have.

Sorry, I’ve update the answer with package.json