92

I've upgraded my project to Angular 6, and everything went fine except the conversion of .angular-cli.json file. From the guide I followed, it was said that this will convert it automatically.

npm install -g @angular/cli

npm install @angular/cli

ng update @angular/cli

However, it was not the case as I still have the old .angular-cli.json

Is there a way to do it automatically / manually?

Community
  • 1
  • 1
Dino
  • 7,779
  • 12
  • 46
  • 85
  • You need to rename it manually – Pardeep Jain May 08 '18 at 11:51
  • 5
    Did you follow [this guide](https://update.angular.io/)? – E. Sundin May 08 '18 at 12:10
  • Don't rename the file. It gets deleted and recreated when you follow the guide. If you rename it, then follow the guide, it won't work. – Kriil May 17 '19 at 23:00
  • I had no luck with the answers below; for me, specifying both `--from` and `--to` did the trick. Admittedly I was updating many packages in the migration process, lots of things could have gone wrong. – effeffe Dec 31 '20 at 10:41

9 Answers9

121

Most likely there were errors in one of those commands. For me, I had to run npm install -g @angular-devkit/core first and then run the commands:

npm install -g @angular/cli

npm install @angular/cli

In the console output of npm install @angular/cli you should see:

================================================================================
The Angular CLI configuration format has been changed, and your existing configuration can
be updated automatically by running the following command:

  ng update @angular/cli
================================================================================

Then you obviously should run ng update @angular/cli to finish off the process.

See the Official Update Guide for additional details.

Kyle Krzeski
  • 6,183
  • 6
  • 41
  • 52
  • 2
    There was an error with npm install @angular/cli ng update, I had to re run it and it worked :) – Dino May 08 '18 at 18:19
  • @WilliamHampshire : I followed the same process, But when I run the command npm install @angular/cli , I got the below error. npm WARN @angular-devkit/schematics@0.0.52 requires a peer of @angular-devkit/core@0.0.29 but none is installed. You must install peer dependencies yourself. npm WARN @schematics/angular@0.1.17 requires a peer of @angular-devkit/core@0.0.29 but none is installed. You must install peer dependencies yourself.npm WARN ajv-keywords@3.2.0 requires a peer of ajv@^6.0.0 but none is installed. You must install peer dependencies yourself. – Abhilash Reddy Oct 01 '18 at 21:59
  • 2
    What I was missing was the `@angular-devkit/core` package, installing that done the trick. – ColinM Dec 07 '18 at 22:14
90

you can automatically update your existing angular-cli.json file to angular.json file by using the below command provided that you are on v6.x.x or greater of angular cli command line tool.

ng update @angular/cli --from=1.7.4 --to=6 --migrate-only

In the above command 1.7.4 is the previous cli version you were using. The --migrate-only flag makes sure that it will only perform a migration but does not update the installed version. Use --to instead of @angular/cli@6 because of https://github.com/angular/angular-update-guide/issues/64.

read more: angular/cli-github

Leponzo
  • 624
  • 1
  • 8
  • 20
rgantla
  • 1,926
  • 10
  • 16
  • Hey, I tried multiple options but your solutions worked. My angular-cli.json is converted to angular.json. But I got another error when I start my application : ng serve Error : ERROR in src/app/workflows/workflow-list/workflow-list.component.ts(441,4): error TS1128: Declaration or statement expected. – Abhilash Reddy Oct 17 '18 at 17:15
  • 1
    Finally this is what worked for me! I had tried so many solutions including all others here as well as the official angular update guide, but whenever I ran `ng update @angular/cli` it never updated angular-cli.json to angular.json. Finally, it worked! Thanks a lot! – Rohan Oct 16 '20 at 07:00
  • 1
    I tried the above command. Don't know why its not working for me. is there any other command which i can try. – Bhushan Khaladkar Nov 30 '21 at 05:48
42

Try running "ng update @angular/cli" twice it will update angular-cli.json to angular.json

UPDATE:

if getting errors like this:

ERROR: The specified command update is invalid, for available options see ng-help.

then you need to run 2 commands as follows

  1. npm install --save-dev @angular/cli@latest.
  2. ng update @angular/cli

this will automatically create angular.json, delete .angular-cli.json and update karma.conf.js, src/tsconfig.spec.json, package.json, and tslint.json

enter image description here

T. Shashwat
  • 1,135
  • 10
  • 23
29

I was trying to update from 5.2 -> 6.1 and was running into an issue where after running npm install @angular/cli@6 followed by ng update @angular/cli@6, (as described by https://update.angular.io/#5.2:6.1) my package.json was being updated but none of the other files like .angular-cli.json or tsconfig.json were, even though I received no errors. I tried executing the update command multiple times but this had no effect.

I ended up running the following 3 commands which worked for me:

npm install @angular/cli@6
ng update @angular/cli
ng update @angular/core@6

The only real change there is the second command. The document says to run ng update @angular/cli@6 but that wouldn't update any of the config files.

MacK
  • 433
  • 4
  • 7
3

For upgrading version from 5.2 to 6.0 , I followed up the following steps.

  • Install Node 8 or above.
  • yarn global add @angular/cli.
  • yarn add @angular/cli.
  • ng update @angular/cli.
  • ng update @angular/core.

    Note: if, after executing ng update @angular/core command,invalid range issue arises,then follow below, just replace the major version in package.json, it'll automatically replace the minor. Resource : Want to upgrade project from Angular v5 to Angular v6

      - npm uninstall -g angular-cli
      - npm cache clean or npm cache verify
      - npm install -g @angular/cli@next
      - then, replace lower versions to higher versions in package.json 
        file.
      - delete node modules folder.
      - run npm/yarn install.
    

After npm install, if you get error of missing src/styles path, then remove the paths given in angular.json file under assets block from ["src/styles", "src/fonts", "src/images", "src/assets", "src/favicon.ico"] to ["assets","favicon.ico"].

  • yarn global add rxjs-tslint (might required).
  • rxjs-5-to-6-migrate -p src/tsconfig.app.json (might required).
  • yarn install @angular/material@6.0.0 (to update material packages).

=> Please note you never need to rename angular.cli.json to angular.json manually!!

** feel free to ask if further queries arises.

Simran kaur
  • 378
  • 3
  • 7
1

Please follow these steps :

1) Update your Angular CLI globally and locally (assuming latest version to be 7)

2) Take your old project and run following command

  • npm install @angular/cli
  • ng update @angular/cli

After running this you have updated all your angular packages to the latest version.

3)Add this package as it is still missing

npm install @angular-devkit/core --save -dev

4) create a fresh new project with ng serve (latest version)

5) Create a new empty file with name angular.json and copy the content of angular.json from the new project into it.

6) Update the name of project accordingly in angular.json

7) Run npm install

8) Run ng serve

9) You are now ready with the latest version of angular.

I followed the above steps to migrate from angular2 to angular7.

  • In case you are getting an error in running ng serve, check the error if it is most probably the entries in angular.json, update them accordingly. For ex - project name, filepaths etc. – Sourabh Jain 543 Oct 24 '18 at 13:10
0

IN CASE OF:
Local workspace file ('angular.json') could not be found.
OR
The serve command requires to be run in an Angular project, but a project definition could not be found.

Upgrade/downgrade to the desired version ( I tried Angular 6 for example )

[sudo] npm install -g -f @angular/cli@6.1.4

Update the local project

ng update @angular/cli@6.1.4

And you're good to go :)

ng serve
0

I had to actually commit every changes or stash them before I could run the command to update the cli as shown in this screenshot.

I did these commands:

npm install --save-dev @angular/cli@latest 

ng update@angular/cli

And committing the changes between these two. Ng serve

Tore Aurstad
  • 3,189
  • 1
  • 27
  • 22
0

This steps will help you create angular.json.I had angular 4 and it worked for me.It should work for older versions.

  1. Create a ng-update-v6.js file inside the Angular project's folder and add the following code given in gist
  2. Run node ng-update-v6.js .angular-cli.json
  3. Now you have angular.json.
  4. Update Package.json ncu -u
  5. Install Updated Node Modules npm i
  6. If you face polyfills import issue (change polyfills.ts)

from

import "core-js/es5/reflect";
import "core-js/es7/reflect";

to

import "core-js/es/reflect";

Credit goes to:Article

Harsh Shah
  • 150
  • 2
  • 6