ng new has stopped working after updating to Angular 6
Asked Answered
C

4

5

Today, I updated my angular cli to the latest version and encountered an error that stops me from creating a new Angular project. Following is the error log that I get after executing ng new app-name :

Error: Schematic "ng-new" not found in collection "@schematics/angular".
    at SchematicEngine.createSchematic (C:\Users\xyz\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\engine\engine.js:155:23)
    at CollectionImpl.createSchematic (C:\Users\xyz\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\src\engine\collection.js:12:29)
    at NodeWorkflow.execute (C:\Users\xyz\node_modules\@angular\cli\node_modules\@angular-devkit\schematics\tools\workflow\node-workflow.js:70:38)
    at Promise (C:\Users\xyz\node_modules\@angular\cli\models\schematic-command.js:141:22)
    at new Promise (<anonymous>)
    at NewCommand.runSchematic (C:\Users\xyz\node_modules\@angular\cli\models\schematic-command.js:140:16)
    at NewCommand.<anonymous> (C:\Users\xyz\node_modules\@angular\cli\commands\new.js:77:25)
    at Generator.next (<anonymous>)
    at C:\Users\xyz\node_modules\@angular\cli\commands\new.js:7:71
    at new Promise (<anonymous>)

In order to solve the problem myself I have reinstalled angular cli as well as npm more than twice. The versions of packages are as follows:

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.6.0
@angular-devkit/core         0.6.0
@angular-devkit/schematics   0.6.0
@schematics/angular          0.6.0
@schematics/update           0.6.0
rxjs                         6.1.0
Angular Cli                  6.0.0
Node                         8.11.1
npm                          5.6.0

Any help would be appreciated.

Edit: I ran ng new from the place where the angular global packages are installed and I am able to create an an application from there. Running it from anywhere else, produces error.

Codicil answered 6/5, 2018 at 9:55 Comment(2)
I think it doesn't update to Angular 6. How can you update it?Loosetongued
I did it as explained by @YakovFain, but, to no result. Angular Cli gets updated to version 6 though, as mentioned above.Codicil
I
10

That happened to me, I thought that was a bug I reported it here, it turned out that I had a folder named node_modules on my home directory!

To make sure this is the same issue with you run following commands

npm ls -g @schematics/angular
npm ls @schematics/angular 

If the output of second command contains

npm ERR! extraneous: @schematics/[email protected] C:\Users\User\node_modules\@angular\cli\node_modules\@schematics\angular

then most likely you have the same issue as it appears that there is a node_modules folder with both the CLI and an old version of @schematics/angular installed locally (C:\Users\User). Remove this to fix this issue.

Please check if it is the case for you too.

Intact answered 8/5, 2018 at 19:55 Comment(1)
You were right. There was a node_modules folder in the home directory and deleting it solved the problem. Thank you.Codicil
D
3

I also got this error when I tried to issue, ng new

I later realized it was as a result of issuing "npm install @angular/cli" which created a node_modules folder, in the directory I was working.

Remove "node_modules" folder, and create your project now with "ng new"

Ps. with the angular 6 upgrade, the ng team must specify that you cant just run "npm install @angular/cli" anywhere you want, but only in the newly created project. I think this is a bit unfair to the newbies to angular

Hope this helps

Desirous answered 14/6, 2018 at 17:50 Comment(0)
M
2

I suspect that your upgrade of Angular CLI didn't go well. Try to uninstall and re-install it again:

npm uninstall @angular/cli -g
npm install @angular/cli -g
Mize answered 6/5, 2018 at 13:40 Comment(2)
I did it two times, at least. Between the uninstall and install, I also ran "npm cache verify".Codicil
After this, you may need to link ng with npm: https://mcmap.net/q/88677/-ng-command-not-found-while-creating-new-project-using-angular-cliBriefs
R
0

Try uninstall and reinstall it again: npm ls -g @schematics/angular npm ls @schematics/angular

Ritzy answered 3/4, 2020 at 12:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.