运行 windows 7 专业版 32 位。
我尝试npm install -g angular-cli
在正常或管理员下运行。
我还尝试将其添加到 PATH: 下的环境变量(C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)
中,但也没有成功。
我究竟做错了什么?
运行 windows 7 专业版 32 位。
我尝试npm install -g angular-cli
在正常或管理员下运行。
我还尝试将其添加到 PATH: 下的环境变量(C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng)
中,但也没有成功。
我究竟做错了什么?
对我来说,它适用于:
npm run ng <command>
添加C:\Users\DELL\AppData\Roaming\npm
到系统变量Path
对我有用。请找到“npm”的适当文件路径
另外,检查您是否已将angular-cli\bin
路径添加到路径变量。
我正在使用WIN 10,只是为了解决这个问题。在cmd中输入以下代码:
npm 配置获取前缀
并将您从顶部获取的路径复制并粘贴到您的计算机环境变量中-->用户变量框-->路径-->编辑--C:\Program Files\nodejs\node_global,您的路径可能不同。
单击确定并重新打开您的 cmd 窗口,输入ng version,然后它就可以工作了!干杯!
只需打开您的命令提示符(以管理员身份运行)。确保node --v
为 6.9.0 或更高版本,并且npm --v
为 3.0.0 r 更高版本。
之后运行以下命令:
npm install -g @angular/cli
一旦安装了角度。您可以在路径中看到 angular cli 的条目
C:\Users\Dell\AppData\Roaming\npm\node_modules\@angular
然后尝试 ng help。它会起作用的。
1) Enter below command on command prompt
npm install -g @angular/cli
2) Make sure that C:\Users\_username_\AppData\Roaming\npm this path is not hidden.
3) Add C:\Users\_username_\AppData\Roaming\npm and
C:\Users\_username_\AppData\Roaming\npm \node_modules@angular\cli\bin to both enviroment variable path.
4) Open new command prompt and type ng help. It will work.
With a command
npm install -g @angular/cli@latest
It works fine, I am able to run ng command now.
I followed below steps for resolution for this issue in Windows 10:
npm install -g @angular/cli@latest
C:\Users\rkota\AppData\Roaming\npm
Same path can be found by running below too:
npm config get prefix
ng --version
you will be able to see CLI version.
几天前,在与其他全局模块遇到相同问题后,我通过添加:
环境表 -> 系统变量 -> 路径:
C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin;C:\Program Files\MongoDB\Server\3.2\bin
请注意,它后面不能有任何空格;
原来是我的问题。
execute following lines in order to solve the issue for both not found and undefined version of ng
npm uninstall -g angular-cli
npm uninstall --save-dev angular-cli
npm cache clean
npm install -g @angular/cli@latest
如果您在执行上述步骤后仍出现错误。然后在下面尝试。
因为它是一个节点脚本。到目前为止,我正在使用以下选项进行创建。
节点 C:\Users\Administrator\AppData\Roaming\npm\node_modules\angular-cli\bin\ng 版本
可能需要符号链接。没有进一步研究。
进一步研究:将路径设置为:%PATH%;C:\Users\Administrator\AppData\Roaming\npm;
在 Windows 中,npm.cmd 文件位于上述路径中。如果设置了上述环境变量,则可以执行为 ng version ng init
General problem is that OS tries to find the PATH variable with ng
keyword and cannot find it.
For me, even after the steps @behrouzmoslem suggested in the top answers to this post I didn't manage to get it work, because after the launch of ng command OS started to respond, but opens up editor file by the path C:\Users\{username}\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
which is actually funny. So, solution is:
Just use npx
before any angular executables.
Eg : npx ng serve
for serving the angular app or npx ng build --watch
to build with watcher.
打开cmd并输入npm install -g @angular/cli
在环境变量中,添加用户变量或系统变量“路径”值=C:\Users\your-user\.npm-packages\node_modules\.bin
在命令中:c:\>cd your-new-project-path
...\project-path\> ng new my-app
或者ng all-ng-commands
关闭 cmd 并使用管理员权限再次打开它或重新启动您的系统。
I faced same issue when i tried to install angular cli locally with command
npm install @angular/cli@latest
After that i got same issue C:\Users\vi1kumar\Desktop\tus\ANGULAR\AngularForms>ng -v 'ng' is not recognized as an internal or external command, operable program or batch file
Than i tried to install it globally
npm install -g @angular/cli@latest
In this case it worked I was wondering that is it not possible to install cli globally ?
After doing some research I found this article very helpful hope it will help someone facing similar issue
I resolved by adding - %AppData%\npm\node_modules@angular\cli\bin\ path to my environment variables path
npm install -g @angular/cli
helped for me instead of npm install @angular/cli
这个几乎对我有用,但我不得不使用: %USERPROFILE%\AppData\Roaming\npm 。在环境变量.../系统变量/路径
然后,当我执行 CMD:"ng -v" 时,我得到了 angular cli 的正确响应。
我在使用 npm v3.10.8 运行的 64 位 Windows 7 上遇到了同样的问题。
npm cache clean
在此之后,我按照此处的提示清除了 npm 缓存https://blogs.msdn.microsoft.com/matt-harrington/2012/02/23/how-to-fix-node-js-npm-permission-problems/ . 这保证没有剩菜。npm install -g angular-cli
瞧。就我而言,我做了以下步骤。
所有程序-> Node JS-> 右键单击 Node.js 命令提示符并选择属性,然后从下面末尾复制的目标字符串中选择
/k "C:\Program Files\nodejs\nodevars.bat"
我启动了 Visual Studio Code 并打开了下面的文件
C:\Users\gochinta\AppData\Roaming\Code\User\settings.json
并在下面给出
// Place your settings in this file to overwrite the default settings
{
"terminal.integrated.shellArgs.windows":
["/k", "C:\\Program Files\\nodejs\\nodevars.bat"]
}
现在我输入ng -v
了我的 Visual Studio Code Terminal 窗口并且它工作了。
我在尝试使用语法“ng new”时遇到了同样的问题,只需通过将现有节点版本从 5.xx 更新到 8.xx 即可解决该问题。成功更新节点后,该语法对我来说非常有效。请更新节点的现有版本。正如 Angular 文档中明确提到的那样,这些命令需要节点版本 >= 6.9.x。如需参考,请查看https://angular.io/guide/quickstart。它明确指出“通过在终端/控制台窗口中运行 node -v 和 npm -v 来验证您至少运行 node 6.9.x 和 npm 3.xx。旧版本会产生错误,但新版本很好”。
I faced same issue on x86, windows 7;
Solution was the .npmrc file at C:\Users{USERNAME}... change the prefix so that it reads "prefix=${APPDATA}\npm"... Thanks to this website for help in resolving it
I am facing same issue and it's get resolved. At my end reason is i install node and CLI using other user profile and now i am running ng command from other user login. Since node and cli installed using other user login node is not finding anything on C:\Users\<user name>\AppData\Roaming
this path and that's why i am getting this error.
I run npm install -g @angular/cli
command and restart my machine. Every thing is working fine.
For me something was wrong in the PATH enviroment variable. I removed all path related to npm and added at the start of PATH this folder:
c:\Users\<your-user-name>\AppData\Roaming\npm\
Make sure you have ;
between paths.
Sometime in the future. Applicable to Windows 8.1 machine. Run the following commands
npm install -g @angular/cli
Log out or restart your machine.
This should add the required env path, rather than doing it manually.
I also tried to play with cmd by setting environment variable path & etc, but simple answer is use nodejs command prompt.
So you no need to set environment variable path or anything. When you insalled nodejs it will give it's command prompt, by using that you us "ng" command, without any settings.
我遇到了同样的问题,即 Visual Studio Code 无法在其内置终端中运行任何 ng 命令。
我将 %AppData%\npm 添加到 Windows 10 的路径中,并且不必重新启动,只需关闭并重新打开 VS Code 并没有看到它。
安装x32 版本的 nodejs而不是x64 版本(即使在 64 位 Windows 机器上)。
我也在关注这个问题,所以我尝试了这个命令,它运行良好。使用这个命令: npm run ng
I had the same problem today and have gone through the following path - (%USERPROFILE%\AppData\Roaming\npm) and came to know that there is some junk data and when I cleared everything under npm directory. Now when I ran (npm install command again). Now everything works fine.
Navigate the directory where you want to create the application and run the command:
PATH="Path where your node is installed";%PATH%
I had the same problem and solved it completely by running VS Code as Administrator.
I used the above mentioned solutions (npm install -g @angular/cli@latest & npm install @angular/cli in my project), tried ng serve both in cmd and VS Code terminal but didn't work, while npm run ng serve could run in VS Code terminal, but I wasn't satisfied with that. After that I set the path in the environment variables exactly like this "C:\Users\TheUserName\AppData\Roaming\npm" and still wasn't able to run ng serve.
Then I ran VS Code as Administrator and it finally worked. It even recognized another command, gulp, which didn't recognize till then, even though I had it also correctly installed. Not sure why it had this behavior and I would like an explanation.
After installation: Go to start Menu Type Environment variable click on "edit the system environment variables", It will open a window In window, click on "Environment variable" button Double click on "Path" then click on new and add the below environment variable C:\Users\\AppData\Roaming\npm (or open run window type %AppData% and open npm folder there. Provide this location in environment variable.)
for me it works only with the flag --force:
npm install -g @angular/cli --force
If everything is fine then you shoud see the folder node_modules in this path:
C:\Users\YOUR_USERNAME\AppData\Roaming\npm\
设置路径=%path%;C:\Users\\AppData\Roaming\npm
PATH environment variable should be updated by adding following path,
C:\Users\xyzname\AppData\Roaming\npm\node_modules\@angular\cli\bin
Because ng file is in bin folder, once this is added for sure ng will be recognized
try to set system variable path with %AppData%\npm\
. and make sure visibility of AppData folder. this folder should be visible (not hidden).
I had to add the npm path to the user PATH environment variable as well. You can do that by running the following PowerShell script as admin:
$path = npm config get prefix
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (($userPath -split ';') -notcontains $path)
{
[Environment]::SetEnvironmentVariable("PATH", ('{0};{1}' -f $userPath, $path), "User")
}
Before try to update the PATH varibles on Windows 7 (x64), run CMD console AS ADMINISTRATOR and ng command works for me, this also applied to VISUAL STUDIO CODE Console.
It worked for me on both CMD CONSOLE / VS CODE
In my case, even though %appdata%\npm
was already in PATH, I had to delete and add it again in the system variable editor. Restarting OS / reinstalling Angular CLI did not help for some reason.
Had the same problem on Windows 10. The user's %Path% environment already had the required "C:\Users\ user \AppData\Roaming\npm".
path command would not show it, but it did show tons of other paths added earlier by other installations.
Turned out I needed to delete some of them from the system's PATH environment variable.
As far as I understand this happens because there's a length limit on these variables: https://software.intel.com/en-us/articles/limitation-to-the-length-of-the-system-path-variable
Probably happens often on dev machines who install lots of stuff that needs to be in the PATH.
Use Node.js command prompt and execute the command
ng version
It should work.
If you're looking to actually find where ng
is located you can then type where ng
and it will show you which ng
is running (eg. C:\Users\USERNAME\AppData\Roaming\npm
). You can then look at your path and see if adding that folder is helpful. The Node.js command prompt adds extra paths that may be missing from your path.
I don't have a global Angular install, only project level. One of my projects kept throwing this error while others with same setup worked fine! I just
node_modules
folder from the projectnpm i
in the projectWorks fine now.
For those using Yarn
After doing a yarn global add @angular/cli
the ng
command was not recognized even after cmd window restart.
The solution for me was to add either
C:\Users\<username>\AppData\Local\Yarn\bin
to the USER environment variable PATH
%LOCALAPPDATA%\Yarn\bin
to the SYSTEM environment variable PATH
.Installing Yarn with npm install -g yarn
did not add those paths for me for some reason, idk if it should or shouldn't but I cant remembering needing to do so previously on other machines I have had.
On Windows 10 pro:
npm install -g @angular/cli
.Note: Don't forget -g
in command.
Set the new path to C:\Users\yourname\AppData\Roaming\npm\node_modules\@angular\cli\bin\ng
It works fine now for me
Add the ng command path from the folder .bin under the node_modules to PATH variable in the system env settings.
e.g: add C:\testProject\node_modules\.bin\
to PATH
Restart your IDE.
You can check in this way. I had the same problem. First, check your user PATH in the environment variable.That must point to "%USERPROFILE%\AppData\Roaming\npm\node_modules\@angular\cli\
Instead of command prompt use the node.js command prompt. Run node.js command prompt from installed program menu. Go to start and search for node.js command prompt. Run it then type ng -v
hit enter. It will work. Let me know your if it helps or not.