Issue
I am not that deep in Angular or Ionic. May be it comes. But for now I’ve the following Problem.
I have an Ionic App "ApplicationLatest". This should start, do some initial checks and fine. But if this checks failes, it should completly switch over/failover to a separate "ApplicationOld".
ApplicationLatest in main.ts :
platformBrowserDynamic().bootstrapModule(AppModuleLatest)
.catch(
err => console.log(err)
);
AppModuleLatest
-> bootstrap: [AppComponent]
About an Emitter during the initial checks I trigger the possible failover
this.parameterLoadError = this.initCheckup.routeError.subscribe((err) => {
platformBrowserDynamic().bootstrapModule(AppModuleOld)
.catch(
err => console.log(err)
);
});
This works fine if I create the debug.apk
=> ionic cordova run android
But when I run the release
=> ionic cordova run android --prod --release
and run the app with a forced failover I got :
ERROR Error: A platform with a different configuration has been created. Please destroy it first.
But if I do the destroyPlatform();
before bootstrapping the AppModuleOld
the screen keeps blank/white.
And an exception is thrown (which I capture with logcat)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: http://localhost/main-es2015.9887f0567239099d41e3.js: Line 1 : ERROR Error: Uncaught (in promise): Error: No NgModule metadata found for 'od'.
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: Error: No NgModule metadata found for 'od'.
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at Gu.resolve (http://localhost/main-es2015.9887f0567239099d41e3.js:1:469088)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at Nu.getNgModuleMetadata (http://localhost/main-es2015.9887f0567239099d41e3.js:1:454054)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at Sh._loadModules (http://localhost/main-es2015.9887f0567239099d41e3.js:1:498940)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at Sh._compileModuleAndComponents (http://localhost/main-es2015.9887f0567239099d41e3.js:1:498616)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at Sh.compileModuleAsync (http://localhost/main-es2015.9887f0567239099d41e3.js:1:497741)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at useClass.compileModuleAsync (http://localhost/main-es2015.9887f0567239099d41e3.js:1:509629)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at zo (http://localhost/main-es2015.9887f0567239099d41e3.js:1:136755)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at Qo.bootstrapModule (http://localhost/main-es2015.9887f0567239099d41e3.js:1:138680)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at ld.initFailover (http://localhost/main-es2015.9887f0567239099d41e3.js:1:529186)
09-25 09:24:02.052 20628 20628 D SystemWebChromeClient: at http://localhost/main-es2015.9887f0567239099d41e3.js:1:529730
There are so many questions in my head…
- Why can it run in debug.apk?
- But generally : Is such a failover possible?
Thanks for any hints and advice!
ionic --version
6.5.0
Angular CLI: 8.3.23
Node: 10.15.3
OS: linux x64
Angular: 8.2.13
Solution
With a little help of some good friends we found a working solutions.
Remember the initialted platfrom
const platformRef = platformBrowserDynamic();
platformRef.bootstrapModule(AppModuleLatest)
.catch(
err => console.log(err)
);
During Failover, take the platformRef, destroy only that one.
this.parameterLoadError = this.initCheckup.routeError.subscribe((err) => {
// Destroy the old one
platformRef.destroy();
//bstrap a new one
platformBrowserDynamic().bootstrapModule(AppModuleOld)
.catch(
err => console.log(err)
);
});
Also I have had to change the following params in angular.json
"buildOptimizer": false,
"aot": false,
"outputHashing": "none",
It’s working for me. On Desktop and (Android) mobile.
Answered By – Tom K.
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0