首页 > 解决方案 > ng :术语“ng”未被识别为 cmdlet 的名称,函数 Visual Studio 代码终端

问题描述

在 VS Code 中,当我运行命令时ng build,出现错误

PS D:\Dashboard\Test1> ng build
ng : The term 'ng' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if   
a path was included, verify that the path is correct and try again.
At line:1 char:1
+ ng build
+ ~~
    + CategoryInfo          : ObjectNotFound: (ng:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

我已经添加了这些环境变量Path

%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
C:\Users\Avind\AppData\Local\Programs\Microsoft VS Code\bin;
C:\Users\Avind\AppData\Roaming\npm;

我怎样才能摆脱这个问题?

注意:我node.jsC:\Program Files\nodejs. 从命令提示符ng new project不工作,但从node.js命令工作。

编辑 1:npm install -g @angular/cli@latest从 VS Code 终端执行后低于 msg 和ngcmd 不工作

PS D:\Path\Test1> npm install -g @angular/cli@latest
npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
C:\Users\Avind\AppData\Roaming\npm\ng -> C:\Users\Avind\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng

> @angular/cli@9.1.9 postinstall C:\Users\AR20095474\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js

+ @angular/cli@9.1.9
updated 1 package in 53.477s

标签: angularvisual-studio-codeterminalng-build

解决方案


您需要安装最新的 Angular cli 才能使 ng 命令正常工作,您可以从命令终端或 Visual Studio 代码终端运行它

npm install -g @angular/cli@latest

如果仍然无法正常工作,请node.jsprogram and feature.


推荐阅读