【问题标题】:The command "ng serve" works in command prompt but doesn't work vs code for the same project命令“ng serve”在命令提示符下工作,但对同一项目的代码不起作用
【发布时间】:2021-11-26 14:47:20
【问题描述】:

我不熟悉使用 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.js npm visual-studio-code angular-cli


    【解决方案1】:

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

    【讨论】:

    • 并确保打开整个项目。不仅是 src 或类似的东西。
    • 还有一点,没有人使用 cmd 提示符。
    • 我什么也没做。但是,当我在 vs 代码终端上尝试 ng serve 时,它起作用了。项目已经生成。我的问题是使用ng serve,如果没有前缀npm run,它就无法工作。不过,感谢您的解决方案。
    猜你喜欢
    • 1970-01-01
    • 2020-08-04
    • 2012-11-15
    • 2018-06-20
    • 2014-03-30
    • 2019-01-26
    • 1970-01-01
    • 2018-11-21
    • 2018-03-21
    相关资源
    最近更新 更多