ng new在更新到Angular 6后已停止工作 [英] ng new has stopped working after updating to Angular 6

查看:166
本文介绍了ng new在更新到Angular 6后已停止工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我将我的angular cli更新到了最新版本,并遇到一个错误,该错误使我无法创建新的Angular项目。以下是执行 ng新的应用程序名称 后得到的错误日志:

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>)

为了自己解决问题,我重新安装了 angular cli npm 两次以上。软件包的版本如下:

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

任何帮助将不胜感激。

编辑:我跑了从安装有角度的全局软件包的地方开始新的操作,我便可以从那里创建一个应用程序。在其他任何地方运行它都会产生错误。

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.

推荐答案

这发生在我身上,我认为那是我报告它的错误在这里,事实证明我的主目录中有一个名为node_modules的文件夹!

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/angular@0.6.0 C:\Users\User\node_modules\@angular\cli\node_modules\@schematics\angular

然后,您很可能遇到相同的问题,因为似乎有一个node_modules文件夹,其中既有CLI也在本地安装了旧版本的@ schematics / angular( C:\Users\User)。删除它可以解决此问题。

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.

请检查是否也适合您。

这篇关于ng new在更新到Angular 6后已停止工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆