Upgrade to Ionic 5 with Angular 9 from Ionic 4 / Angular 7 - ionic-framework

There is a great tutorial video on the official Ionic YouTube channel which will show you a best-case scenario for upgrading to Ionic 5 and Angular 9.
However for my simple prototype app that I had made last year (just a demo that let me reorder a list) I tried to update but almost immediately came off the rails.
It turned out to be using "#angular/core": "^7.2.2" which broke the app from ionic serve because it was expecting Angular 8.
Then I tried to run the ng upgrade but got hit with incompatible peer dependencies for codelyzer, #ionic/angular-toolkit, and #angular/http.
So I tried to upgrade to Angular 8 first with npm i #angular/core#"~8.x.x" but that failed as it needed npm i zone.js#~0.9.1.
How can I update successfully to the latest and greatest?

So for people coming from angular 7 it seems for this project the correct upgrade commands are:
npm i #ionic/angular#latest
npm i zone.js#~0.9.1
npm i #angular/core#"~8.x.x"
npm i #ionic/angular-toolkit#latest
npm i codelyzer#latest
npm remove #angular/http
ng update #angular/core #angular/cli --allow-dirty
and it finally updated everything. However I did see a warning saying Package not installed: "--allow-dirty". Skipping.
However, then after that I dared to try ionic build and it failed with this error, which got me stuck for another 15 minutes:
zone-flags.ts is missing from the TypeScript compilation.
It seems that the polyfills.ts uses the .ts extension in the include which is breaking the compilation.
I changed this line in polyfills.ts:
import './zone-flags.ts';
To this:
import './zone-flags';
AND IT COMPILED.
But did it ionic serve?
No. No it did not.
The browser showed this in the console:
Error: Angular JIT compilation failed: '#angular/compiler' not loaded!
So after some more searching, I found that if you open main.ts and then add
import '#angular/compiler';
Near the top then all will be right and good with the world once more...
...unless your project then needs the markup breaking changes resolving, but you're on your own for that.

Related

IONIC 5 ionic serve produces Error: NGCC failed

I created a new ionic 5 project by using
ionic start myApp blank
When I run the project in browser using ionic serve it has given the following error
Error: NGCC failed
I figured out the problem my self
The problem was when I was installing the latest npm packages
it was installing the typescript: 4.0.2 and thats why the NGCC error
occured
run the following command and it will work,
npm i typescript#">=3.9.2 <4.0.0”
Or in future some one faces this error this is about the typescript version so just install the valid typescript and you will fix the ngcc error

How to Create Custom SplashScreen on Ionic?

I want show custom splash screen with animation. I tried add LottieSplashScreen plugin but i can't do this.
Tried with this code
cordova plugin add cordova-plugin-lottie-splashscreen
But i facing
'sh' is not recognized as an internal or external command,
operable program or batch file.
Failed to install 'cordova-plugin-lottie-splashscreen': Error: Hook failed with error code ENOENT: C:\Users\bbara\Desktop\GuvercinSepetim\plugins\cordova-plugin-lottie-splashscreen\hooks\ios\update_pod_repo.sh
at C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\cordova-lib\src\hooks\HooksRunner.js:224:23
at _rejected (C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:864:24)
at C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:890:30
at Promise.when (C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:1142:31)
at Promise.promise.promiseDispatch (C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:808:41)
at C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:624:44
at runSingle (C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:137:13)
at flush (C:\Users\bbara\AppData\Roaming\npm\node_modules\cordova\node_modules\q\q.js:125:13)
at processTicksAndRejections (internal/process/next_tick.js:74:9)
Hook failed with error code ENOENT: C:\Users\bbara\Desktop\GuvercinSepetim\plugins\cordova-plugin-lottie-splashscreen\hooks\ios\update_pod_repo.sh
You are running a cordova node but not ionic cordova:
cordova plugin add cordova-plugin-lottie-splashscreen
According to ionic documentation:
npm install #ionic-native/lottie-splash-screen
ionic cordova plugin add cordova-plugin-lottie-splashscreen
And here is the referance:
https://ionicframework.com/docs/native/lottie-splash-screen
And here is the github reposatory of the plugin :
https://github.com/timbru31/cordova-plugin-lottie-splashscreen
Try looking into Capacitor instead of Cordova. You can still use all your Cordova libraries, but the Capacitor build is a bit cleaner. I followed this tutorial and found it very useful with good tools. It worked for me first time, which is never the case with some Ionic stuff!
https://enappd.com/blog/icon-splash-in-ionic-react-capacitor-apps/114/
The issue you are describing was fixed in the v0.8.1 release. It originated from preparing/building the iOS platform on a Windows machine - which won't work anyways. Because cordova-ios supports recent Pod installations out of the box, it's no longer required to sync the repo, i.e, the hook is obsolete. However, the lottie plugin won't fail anymore.
Side note: I'm the author of this plugin.

Adding Cordova to ionic 4 failing

I have been trying to add Cordova to ionic 4 projects but i keep getting an error and I know prior now i was able to add the same but not anymore.
Whenever i run the below command its exiting with error code 1
ionic cordova plugin add cordova-plugin-x-socialsharing
I don't actually know what i am doing wrong or Cordova is no longer working
I have asked in the ionic forum but no response yet
https://forum.ionicframework.com/t/not-able-to-add-cordova-to-ionic-4/177323

Ionic CLI: [ERROR] Gulpfile (or dependent module) not found: .\gulpfile.js

Senario
I recently upon running an Ionic 3 app, updated (well accidentally) the Ionic CLI version. Now upon running the build from command line, it produces the following error every time and halts the build:
In the error message it says to disable the gulp integration by running the command ionic config set gulp.enabled false which I did. But still getting the same error. I also tried to add the command to the start script of package.json to no avail (not needed though since it seems the config is set globally).
Any help would be appreciated.
Ionic CLI version: 3.9.2
Finally figured out what the problem was. Even if Gulp integration has been disabled with the command ionic config set gulp.enabled false, as long as Gulp is a Dev dependency (i.e. there is a reference to it in the package.json under devDependencies) the Ionic CLI would (well, logically) assume that the Ionic project has a dependency on Gulp, therefore would throw the error (see original post).
Solution
The solution for a case where you don't want Gulp integration, apart from disabling it by running the command ionic config set gulp.enabled false, is to also make sure Gulp is NOT under the devDependencies in the package.json file.
Hope this helps anyone else with a similar issue.
NOTE: Not sure from which version onwards Ionic requires integration with Cordova and Gulp in the shape of ionic.config.json file. Anyway, the above solution will be relevant for a similar case in any of those versions.

How to keep both ionic 1, 3, version in my system

Initaially i was working with ionic 1.7.6 version with many apps. And by today some how i have changed to version 3.0.0. Now when i open my old projects under package.json i see the version as 3.0.0 instead of 1.7.6. And when i do sudo ionic build android it throws me some error to upgrade the version.
So now i have uninstall the ionic & cordova from my system.
Now i want to keep ionic 1 version 1.7.6 as well as ionic 3 version 3.0.0 how can i do it now.
so when ever i open the ionic 1 project i need to work on angularjs with ionic 1 version.
And when ever i open the project that i have created with version 3 i need to work with latest version of angular is with ionic 3..
please some one expalain me what should i need to do ??
Thank in advance !
I suspect you have installed ionic globally. If you want to run the local/project version of ionic you need to sudo ./node_modules/ionic/ionic ....
This will be the version of ionic as defined in the package.json of the project.
You can tuck this nicely away however using npm scripts (in your package.json):
e.g.
"scripts": {
"ionic": "sudo ./node_modules/ionic/ionic build "
}
Ten simply execute npm run ionic -- android