Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/26.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular ng:术语';ng';未识别为cmdlet函数Visual Studio代码终端的名称_Angular_Visual Studio Code_Terminal - Fatal编程技术网

Angular ng:术语';ng';未识别为cmdlet函数Visual Studio代码终端的名称

Angular ng:术语';ng';未识别为cmdlet函数Visual Studio代码终端的名称,angular,visual-studio-code,terminal,Angular,Visual Studio Code,Terminal,在VS代码中,当我运行命令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 pat

在VS代码中,当我运行命令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;
我怎样才能解决这个问题

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

编辑1:执行
npm安装-g@angular后/cli@latest
来自VS代码终端,低于msg且
ng
cmd不工作

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
此处请确保已安装Angular CLI

npm install -g @angular/cli
ng new project

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

npm install -g @angular/cli@latest

如果仍然无法工作,请从
程序和功能中卸载并重新安装
node.js
,我也遇到了同样的问题。我在一个新选项卡中重新打开了CMD,并键入了如下内容:

ng g c componentname

点击回车键,它对我有效。

这对我有效,但在我的情况下,在上面尝试是不起作用的

Run this command -> Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
参考:

方法1:

步骤1:运行命令“Set ExecutionPolicy RemoteSigned-Scope CurrentUser”

运行此命令时,可以看到系统已将当前用户的所有策略设置为远程。完成此过程需要几秒钟

步骤2:在此处输入图像描述获取执行策略-列表 运行此命令时,监视器屏幕上会显示一些策略 验证当前用户的策略是否为RemoteSigned。 ->如果是,现在应该可以了。 如果没有,请尝试以下方法2:

方法2: 在路径C:\Users%username%\AppData\Roaming\npm\and中找到文件“ng.ps1” 将其从目录中删除。 如果您不知道文件扩展名,请右键单击文件->转到属性并检查文件扩展名


注意:-请不要删除任何其他文件。请确保仅删除ng.ps1文件。

我需要从何处执行它?任何位置都不重要,它是全局安装。执行此操作后,我可以从cmd创建项目,但VS代码仍然没有运行ng命令。如果在安装CLI后不关闭VS代码,请尝试重新启动。并显示结果是否安装了节点和npm?您是以管理员身份运行的吗?我有node.js和npm,正如上面给出的env变量pl check。我在cmd上面运行了admin still VS代码显示错误。我可以清楚地看到angular cli已安装,我认为您正在做一些愚蠢的事情,我从昨天开始就一直在做。可能的原因是什么?可能是尝试在命令提示符下执行该命令,如果在终端中执行,请查看
npm config get bin links
返回什么?@kai-in VS-code-terminal说
true
。您还可以检查
C:\Users\Avind\AppData\Roaming\npm
中是否有一个名为
ng.cmd
?@kai-是,此文件位于同一路径中。