【问题标题】:ng command is not working when using from a different folder从其他文件夹使用时,ng 命令不起作用
【发布时间】:2021-06-21 22:21:35
【问题描述】:

我为新的 Angular 项目选择了不同的文件夹
当我输入任何形式的 ng 命令时,我都会收到此错误

'ng' is not recognized as an internal or external command, operable program or batch file.



我试过命令

 npm install -g @angular/cli

只需打开 cmd 以及来自 Visual Studio 代码的 Angular 项目文件夹。
这就是我得到的

npm WARN deprecated request@2.88.2: request has been deprecated, see 
https://github.com/request/request/issues/3142
npm WARN deprecated har-validator@5.1.5: this library is no longer 
supported
C:\Users\hp\AppData\Roaming\npm\ng -> 
C:\Users\hp\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng

> @angular/cli@12.0.5 postinstall 
C:\Users\hp\AppData\Roaming\npm\node_modules\@angular\cli
> node ./bin/postinstall/script.js

+ @angular/cli@12.0.5
updated 1 package in 45.097s

【问题讨论】:

    标签: angular npm angular-cli


    【解决方案1】:

    试试上面@Filip Huhta 的答案。 如果它不起作用并且由于某些包无法被覆盖而无法安装 Angular,请尝试以下操作:

    npm install -g @angular/cli --force
    

    【讨论】:

      【解决方案2】:

      您可以尝试三种不同的方法来解决您的问题:

      1. 尝试为 Angular CLI 配置您的环境路径。

      转到:环境表 -> 系统变量 -> 路径

      示例路径: C:\Users\USERNAME\AppData\Roaming\npm

      2.如果您添加了angular-cli\bin,您也可以仔细检查。

      例子:

      alias ng="path-to-your-global-node-modules/angular-cli/bin/ng"

      ng 文件在npm 文件夹中的位置)

      3.试试这个命令也可以解决这个问题:

      npm link @angular/cli

      ( 有时你需要写sudo npm link @angular/cli 才能得到这个 工作)

      【讨论】:

      • 我将 C:\Users\hp\AppData\Roaming\npm 添加到系统路径变量中...但仍然无法正常工作...
      • 以及如何知道angular-cli\bin的路径?
      猜你喜欢
      • 1970-01-01
      • 2018-11-22
      • 2021-12-30
      • 1970-01-01
      • 2020-09-25
      • 2018-07-27
      • 1970-01-01
      • 2010-10-31
      • 2018-09-07
      相关资源
      最近更新 更多