当我尝试通过以下方式安装 CLI 时收到 npm 警告:npm install -g @angular/cli:
C:\Users\myuser>npm install -g @angular/[email protected]
npm WARN deprecated [email protected]: This module is not supported, and leaks memory. Do not use it. Check out lru-cache if you want a good and tested way to coalesce async requests by a key value, which is much more comprehensive and powerful.
npm WARN deprecated @npmcli/[email protected]: This functionality has been moved to @npmcli/fs
npm WARN deprecated [email protected]: This package is no longer supported. Please use @npmcli/package-json instead.
npm WARN deprecated [email protected]: This package is no longer supported.
npm WARN deprecated [email protected]: Rimraf versions prior to v4 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: Glob versions prior to v9 are no longer supported
npm WARN deprecated [email protected]: This package is no longer supported.
npm WARN deprecated [email protected]: This package is no longer supported.
added 1 package, changed 271 packages, and audited 273 packages in 44s
39 packages are looking for funding
run npm fund for details
found 0 vulnerabilities
C:\Users\myuser>ng version
"ng" is not recognized as an internal or external command,
operable program or batch file.
我做错了什么?或者说怎样才能解决呢?谢谢!
我本来希望安装 Angular CLI。
看起来 Angular CLI 没有正确安装,或者您系统的 PATH 环境变量不包含全局 npm 目录。以下是解决此问题的方法:
检查npm路径配置并运行以下命令来检查npm安装全局包的位置:
npm config get prefix
确保此命令返回的路径包含在系统的 PATH 环境变量中。
将npm路径添加到系统环境变量中: 打开系统上的“环境变量”设置。 添加 npm 全局路径(例如 C:\Users\your_user\AppData\Roaming pm) 到 PATH 变量。
重新安装 Angular CLI:卸载 CLI,清除 npm 缓存,然后重新安装:
npm uninstall -g @angular/cli
npm cache clean --force
npm install -g @angular/cli
验证安装:运行以下命令来验证安装:
ng version
如果仍然无法识别 ng 命令,则 npm 本身可能存在问题。考虑更新 npm 或重新安装 Node.js.