正确重新安装 Angular

J.D*_*Doe 2 angular

我在 Angular 中的依赖项出现问题,所以我在我的项目中重新安装了它。所以,我所做的是:

npm uninstall -g angular-cli
npm cache clean or npm cache verify
npm install -g @angular/cli@latest

rm -rf node_modules
npm uninstall --save-dev angular-cli
npm install --save-dev @angular/cli@latest
npm install
Run Code Online (Sandbox Code Playgroud)

但是现在,当尝试使用 npm start 或 ngserve 时,会发生这种情况

The serve command requires to be run in an Angular project, but a project definition could not be found.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! angular@0.0.0 start: `ng serve`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the angular@0.0.0 start script.
Run Code Online (Sandbox Code Playgroud)

除此之外,当尝试 npm install 命令时,我收到奇怪的警告:

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@1.2.9 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@1.2.9: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

audited 7337 packages in 4.116s
found 20 vulnerabilities (3 low, 14 moderate, 3 high)
Run Code Online (Sandbox Code Playgroud)

它在卸载之前就起作用了(除了依赖项),所以我真的很沮丧。

我在谷歌上发现这个问题的第一件事当然是

Angular CLI 错误:serve 命令需要在 Angular 项目中运行,但找不到项目定义

但这样做之后,问题依然存在。

如何正确重新安装 Angular?

小智 8

尝试这个,

    npm uninstall -g angular-cli
    npm uninstall -g @angular/cli
    npm cache clean
    npm install -g @angular/cli@latest
Run Code Online (Sandbox Code Playgroud)

然后,当它成功完成后,您可以尝试:

ng--版本