只有Visual Studio Code无法识别“ ng”命令

时间:2020-01-18 20:04:12

标签: angular npm command-line-interface

我看到有很多有关ng无法被计算机识别的问题,但我的问题不完全是这样。

每个具有命令外壳的软件都可以识别ng,只有vs代码不能识别。

IntelliJ?检查。

重击吗?检查。

Windows命令提示符?检查。

VS代码?不。

使用npm run ng可以使其正常工作,但这很烦人,而不是应该如何工作。

作为参考,ng已经在我的路径上,现在看起来像这样:

C:\Users\username\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng

除了在VS代码上,它为什么可以在任何地方都可以使用?

3 个答案:

答案 0 :(得分:1)

找出问题所在:我在VS Code中使用了Powershell而不是CMD。

编辑:另外,要在Powershell中使用它,我需要使用命令“ Set-ExecutionPolicy Unrestricted”

答案 1 :(得分:1)

我遇到了这个问题,我的 VS-code 终端没有运行 ng 命令。 My terminal doesn't run ng serve.

我从“C:\Users\PC\AppData\Roaming\npm”中删除了文件“ng.ps1”

ng.ps1 file in "C:\Users\PC\AppData\Roaming\npm".

现在,我的 VS-code 终端运行 ng 命令。 My terminal runs ng serve.

附言 我在 tsc (type-script) 上遇到了同样的问题,当我删除 tsc.ps1 时,我的终端开始运行 tsc 命令。

答案 2 :(得分:0)

1- Press Ctrl+Shift+P to show all commands.
2- Type shell in the displayed text box to filter the list.
3- Select Terminal: Select Default Shell.
4- You will be prompted to Select your preferred terminal shell, you can change this 
   later in your settings or follow the same process as we do now
5- Select Command Prompt (cmd.exe)
6- Click the Delete Icon in the shell pane to remove the existing terminal.
7- Press Ctrl +back tick(which is the character before the number one in your keyboard) 
   (or View > Terminal in menu) to open a new terminal pane