ng :术语“ng”未被识别为 cmdlet 的名称,函数 Visual Studio Code Terminal

Arv*_*iya 4 terminal visual-studio-code angular

在 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
Run Code Online (Sandbox Code Playgroud)

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

%USERPROFILE%\AppData\Local\Microsoft\WindowsApps;
C:\Users\Avind\AppData\Local\Programs\Microsoft VS Code\bin;
C:\Users\Avind\AppData\Roaming\npm;
Run Code Online (Sandbox Code Playgroud)

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

注意:我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
Run Code Online (Sandbox Code Playgroud)

Saj*_*ran 11

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

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

如果仍无法正常工作,请卸载并重新安装node.jsprogram and feature


Cor*_*rrM 9

如此处的Angular CLI所示,请确保您安装了 Angular CLI。
\n您可以从系统上的任何位置运行此命令。

\n
npm install -g @angular/cli\nng --version\n
Run Code Online (Sandbox Code Playgroud)\n

它应该打印如下内容:

\n
     _                      _                 ____ _     ___\n    / \\   _ __   __ _ _   _| | __ _ _ __     / ___| |   |_ _|\n   / \xe2\x96\xb3 \\ | \'_ \\ / _` | | | | |/ _` | \'__|   | |   | |    | |\n  / ___ \\| | | | (_| | |_| | | (_| | |      | |___| |___ | |\n /_/   \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_|       \\____|_____|___|\n                |___/\n\n\nAngular CLI: 13.1.2\nNode: 16.13.1\nPackage Manager: npm 8.1.2\nOS: win32 x64\n\nAngular:\n...\n\nPackage                      Version\n------------------------------------------------------\n@angular-devkit/architect    0.1301.2 (cli-only)\n@angular-devkit/core         13.1.2 (cli-only)\n@angular-devkit/schematics   13.1.2 (cli-only)\n@schematics/angular          13.1.2 (cli-only)\n
Run Code Online (Sandbox Code Playgroud)\n


小智 5

这对我有用。尝试以前的答案对我来说不起作用。

运行这个命令

Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
Run Code Online (Sandbox Code Playgroud)

参考:

ng :无法加载文件 \AppData\Roaming\npm\ng.ps1。文件 npm\ng.ps1 未经过数字签名 运行命令时出现 Angular 错误