首页 > 解决方案 > 命令“ng serve”在命令提示符下工作,但对同一项目的代码不起作用

问题描述

我不熟悉使用 Angular 或 Visual Studio 代码。我安装了运行良好的 node.js 和 npm。运行项目ng serve的命令,在命令提示符下完美运行。但是,当我切换到 vs 代码的终端区域并运行相同的命令ng serve时,它会引发如下错误。

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 serve
+ ~~
    + CategoryInfo          : ObjectNotFound: (ng:String) [], CommandNotFoundException
    + FullyQualifiedErrorId : CommandNotFoundException

再说一次,如果我使用npm run ng serve,它的工作方式就像它在 vs code 终端中的工作方式一样。它是如何工作的?如果没有,我应该怎么做才能使它仅用于ng serve运行项目?

标签: node.jsnpmvisual-studio-codeangular-cli

解决方案


我认为您可以Shift + 右键单击​​您的文件夹,这样您就可以打开 powershell,然后执行npm install -g @angular/cli然后生成您的项目。我认为它应该工作。


推荐阅读