运行windows 7 Professional 32bit。

我试着在normal或admin下运行npm install -g angular-cli。

我还尝试将它添加到PATH: (C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)下的环境变量中,也没有成功。

我做错了什么?


当前回答

我必须将npm路径添加到user path环境变量中。你可以以管理员身份运行以下PowerShell脚本:

$path = npm config get prefix    
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")

if (($userPath -split ';') -notcontains $path) 
{
    [Environment]::SetEnvironmentVariable("PATH", ('{0};{1}' -f $userPath, $path), "User")
}

其他回答

我根据图解决了这个问题:

在CMD下运行

 npm install -g @angular/cli

然后

(在Windows 10中打开)控制面板\所有控制面板项\系统 或按图

步骤1:

第二步:

步骤3:

目的:

添加缺少的ng路径

下面是你需要添加的新环境变量:c:\ users \ pk\ appdata \漫游\npm\node_modules\@angular\cli\bin

最后,重新启动所有打开的命令提示符并重试。

将C:\Users\DELL\AppData\Roaming\npm添加到系统变量路径对我来说很有效。请找到相应的“npm”文件路径

另外,检查是否已经将angular-cli\bin路径添加到path变量中。

对我来说,它适用于:

npm run ng <command>

I was having the same issue when tried with the syntax "ng new " and solved that simply by updating the existing node version from 5.x.x to 8.x.x. After successful updation of node, the syntax worked perfectly for me. Please update the existing version of node. As it is clearly mentioned in angular documentation that these commands require the node version >= 6.9.x. For reference please check https://angular.io/guide/quickstart. It clearly states "Verify that you are running at least node 6.9.x and npm 3.x.x by running node -v and npm -v in a terminal/console window. Older versions produce errors, but newer versions are fine".

在尝试更新Windows 7 (x64)上的PATH变量之前,运行CMD控制台AS ADMINISTRATOR和ng命令对我有用,这也适用于VISUAL STUDIO CODE控制台。

它为我工作在CMD控制台/ VS CODE