In Ionic v4, when I'm run app bundled in production mode (ionic cordova build android --prod), console says 'Could not find cordova.js script tag. Plugin loading may fail.' and some things of the app like fonts are unload(I see Roboto Font and not my custom font). Otherwise, when I'm triying to compile without production mode**(ionic cordova build android)**, the app ran without console errors.
My Ionic info:
ionic (Ionic CLI) : 4.12.0 Ionic Framework : @ionic/angular 4.2.0 @angular-devkit/build-angular : 0.13.8 @angular-devkit/schematics : 7.2.4 @angular/cli : 7.3.8 @ionic/angular-toolkit : 1.4.1
Cordova:
cordova (Cordova CLI) : 8.1.2 ([email protected]) Cordova Platforms : android 7.1.4 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 3.1.2, (and 7 other plugins)
Does anyone face this problem as well?
Cheers,
In dev environment the address is cordova.js and the file is found. In prod the file name gets hashed into something like cordova.4bdae3fd4f9978d7dcd8.js.
Therefore you need to modify the function findCordovaPath() to
function findCordovaPath () {
var path = null;
var scripts = document.getElementsByTagName('script');
var startterm = '/cordova.';
var term = '/cordova.js';
for (var n = scripts.length - 1; n > -1; n--) {
var src = scripts[n].src.replace(/\?.*$/, ''); // Strip any query param CB-6007).
var idx = src.indexOf(startterm);
if (idx >= 0){
term = src.substring(idx+1);
}
if (src.indexOf(term) === (src.length - term.length)) {
path = src.substring(0, src.length - term.length) + '/';
break;
}
}
return path;
}
I had the same problem when I migrated from ionic 3 to ionic 4. It disappeard after I started a freshly new project (with tabs default) and copied the code.
There seems someone to have found a solution:
I no longer have that problem. In angular.json, I set buildOptimizer and AoT to false, then I was able to build with --prod. When I reactivated AoT, I see the problem in the log. The dependency injection was doing the wrong way during the migration. Source: Github
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With