Angular CLI 从 6 升级到 7 不工作

Angular CLI upgrade from 6 to 7 not working

我尝试使用 angular CLI github 页面上的说明在我的 mac 上升级节点和 angular CLI,但升级没有不工作。升级后说它安装了 Angular CLI v7.1.4,如果我安装 "ng --version",它仍然显示旧的 6.2.1 版本。有趣的是,看起来 npm install 将代码放入节点 10.10,这是节点的旧版本而不是新版本 11.6。如何安装正确版本的 angular CLI?

MacBook-Pro:~ XXXXXXXXXX$ npm uninstall -g @angular/cli
removed 360 packages in 2.149s

MacBook-Pro:~ XXXXXXXXXX$ npm cache verify
Cache verified and compressed (~/.npm/_cacache):
Content verified: 512 (18309157 bytes)
Index entries: 778
Finished in 0.834s

MacBook-Pro:~ XXXXXXXXXX$ npm install -g @angular/cli
/usr/local/Cellar/node/10.10.0/bin/ng -> /usr/local/Cellar/node/10.10.0/lib/node_modules/@angular/cli/bin/ng

> fsevents@1.2.4 install /usr/local/Cellar/node/10.10.0/lib/node_modules/@angular/cli/node_modules/fsevents
> node install

node-pre-gyp WARN Tried to download(404): https://fsevents-binaries.s3-us-west-2.amazonaws.com/v1.2.4/fse-v1.2.4-node-v67-darwin-x64.tar.gz 
node-pre-gyp WARN Pre-built binaries not found for fsevents@1.2.4 and node@11.6.0 (node-v67 ABI, unknown) (falling back to source compile with node-gyp) 
  SOLINK_MODULE(target) Release/.node
  CXX(target) Release/obj.target/fse/fsevents.o
../fsevents.cc:63:6: warning: field 'async_resource' will be initialized after
      field 'lockStarted' [-Wreorder]
   : async_resource("fsevents:FSEvents"), lockStarted(false) {
     ^
1 warning generated.
  SOLINK_MODULE(target) Release/fse.node
  COPY /usr/local/Cellar/node/10.10.0/lib/node_modules/@angular/cli/node_modules/fsevents/lib/binding/Release/node-v67-darwin-x64/fse.node
  TOUCH Release/obj.target/action_after_build.stamp
+ @angular/cli@7.1.4
added 360 packages from 195 contributors in 20.723s
MacBook-Pro:~ breynolds$ ng --version

     _                      _                 ____ _     ___
    / \   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|
   / △ \ | '_ \ / _` | | | | |/ _` | '__|   | |   | |    | |
  / ___ \| | | | (_| | |_| | | (_| | |      | |___| |___ | |
 /_/   \_\_| |_|\__, |\__,_|_|\__,_|_|       \____|_____|___|
                |___/


Angular CLI: 6.2.1
Node: 11.6.0
OS: darwin x64
Angular: 
... 

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.8.1
@angular-devkit/core         0.8.1
@angular-devkit/schematics   0.8.1
@schematics/angular          0.8.1
@schematics/update           0.8.1
rxjs                         6.2.2
typescript                   2.9.2

答案是节点的 n 版本管理器妨碍了 angular CLI 安装。当我使用 n 列出可用版本时,我只安装了一个版本的节点,但它正在安装到旧版本的节点中。我卸载了 n,因为它在我的机器上导致了多个问题,现在 Angular CLI 安装正确。

sudo npm uninstall -g n

然后我安装了 Angular CLI

npm install -g @angular/cli@latest

现在 angular CLI 工作正常。