“npm”不能识别为内部或外部命令、可操作程序或批处理文件

时间:2022-07-05 23:12:42

I am completely new to nodejs. I am trying to get nodejs to work on my Windows 2008 box in order to install Karma which I would use for TDDing my AngularJs code. I have done the following steps so far

我对node . js完全陌生。我正在尝试让nodejs在我的Windows 2008框上工作,以便安装Karma,我将用它来清除AngularJs代码。到目前为止,我已经完成了以下步骤

  1. Install using Chocolatey ==> npm is not recognised
  2. 使用Chocolatey ==> npm进行安装是不被认可的
  3. Install using 64-bit nodejs installer from nodejs.org ==> npm is not recognised
  4. 在nodejs.org == => npm中安装使用64位nodejs安装程序是不被认可的。
  5. At this stage, running where npm gives me c:\User\<Username>\AppData\Roaming\npm which has nothing in it
  6. 在这个阶段,运行npm给我的c:\User\ \AppData\漫游\npm,里面什么都没有。
  7. I figure out that nodejs is installed in C:\Program Files\nodejs. Opening a command prompt in this directory makes npm work fine.
  8. 我找出nodejs C:\Program Files\nodejs.安装在此目录中打开命令提示符可以使npm正常工作。
  9. So I added C:\Program Files\nodejs to PATH only to get the same error again that npm is not recognized
  10. 所以我添加了C:\Program Files\nodejs路径只得到同样的错误再次npm并不认可
  11. One of the github issues on nodejs repository says that I need to restart the machine and it would fix. But that has not helped so far
  12. nodejs存储库上的一个github问题说,我需要重新启动机器,它会修复。但到目前为止,这并没有起到什么作用
  13. I do see a Node.js icon in my Start -> Programms mennu which takes me to nodejs console but not sure what to do with that.
  14. 我确实看到了一个节点。在我的开始->程序mennu把我带到nodejs控制台,但不知道该怎么做。

Have I missed any important step in the process?

我错过了这个过程中的重要一步吗?

Edit

I figured out that if I open "Nodejs command prompt" from program files, then npm is recognized. How do I make it work on a normal command prompt?

我发现如果我从程序文件中打开“Nodejs命令提示符”,那么npm就被识别了。如何使它在正常的命令提示符上工作?

Edit

After node I started facing a similar problem with another application. I posted this question on superuser and as rightly pointed out by the accepted answer, I had an additional quote in my PATH which was causing issues with all the paths added after the quote. I have a feeling that some Chocolatey install adds this troubling quote but I am just not sure which one.

在节点之后,我开始面对另一个应用程序的类似问题。我在superuser上发布了这个问题,正如所接受的答案所正确指出的那样,我的路径中有一个附加的引用,它导致了在引用之后添加的所有路径的问题。我有一种感觉,一些巧克力的安装添加了这个麻烦的报价,但我只是不确定是哪一个。

18 个解决方案

#1


209  

Just add:

添加:

;C:\Program Files\nodejs\

To the end of your Path variable on the "User variable" section of the Environment Variables on the System Properties.

在系统属性上的环境变量的“用户变量”部分的路径变量的末尾。

After that, reopen your command prompt and type

然后,重新打开命令提示符并输入

npm

This should work.

这应该工作。

#2


56  

Don't forget to reboot your computer after installing node! That one got me.

安装node后不要忘记重新启动您的计算机!一个让我。

#3


14  

To elaborate on Breno's answer... For Windows 7 these steps worked for me:

详细阐述布里诺的回答……对于Windows 7,这些步骤对我起了作用:

  1. Open the Control Panel (Click the Start button, then click Control Panel)
  2. 打开控制面板(单击“开始”按钮,然后单击“控制面板”)
  3. Click User Accounts
  4. 单击用户帐户
  5. Click Change my environment variables
  6. 单击“更改环境变量”
  7. Select PATH and click the Edit... button
  8. 选择路径并点击编辑…按钮
  9. At the end of the Variable value, add ;C:\Program Files\nodejs
  10. 在变量值的末尾,添加;C:\程序文件\nodejs
  11. Click Ok on the "Edit User Variable" window, then click Ok on the "Environment Variables" window
  12. 在“编辑用户变量”窗口上单击Ok,然后在“环境变量”窗口上单击Ok
  13. Start a command prompt window (Start button, then type cmd into the search and hit enter)
  14. 启动命令提示窗口(启动按钮,然后输入cmd到搜索并按回车键)
  15. At the prompt (C:\>) type npm and hit enter; you should now see some help text (Usage: npm <command> etc.) rather than "npm is not recognized..."
  16. 在提示符(C:\>)输入npm,点击回车;您现在应该看到一些帮助文本(使用:npm 等),而不是“npm不被识别……”

Now you can start using npm!

现在你可以开始使用npm了!

#4


9  

I had the same problem described by Ashu, but in addition to that, the PATH entry for nodejs was terminated by a backslash:

我遇到了Ashu所描述的相同问题,但除此之外,nodejs的路径条目被反斜杠终止:

C:\Program Files\nodejs\

I also had to remove that final backslash in order to have it work.

我还必须删除最后的反斜杠才能让它工作。

#5


8  

Don't forget to run cmd as admin.

不要忘记管理cmd。

#6


8  

I faced the exact same issue and notice that after installing node.js there was a new path entry in the user variable section for PATH with value --> c:\User\\AppData\Roaming\npm. Also the Path entry in the system variable is appended with --> C:\Program Files\nodejs. Now since user variable has preference over system you have two options to fix this. Either delete the path from user variable or correct the right path (C:\Program Files\nodejs). Restart CMD and it should work.

我也遇到了同样的问题,在安装node之后注意到了这一点。在带有值的路径的用户变量部分有一个新的路径条目——> c:\用户\应用程序数据\漫游\npm。也进入系统变量的路径- - > C:\Program Files\nodejs.附加既然用户变量对系统有偏好,有两个选项可以解决这个问题。从用户变量中删除路径,或者纠正正确的路径(C:\程序文件\nodejs)。重新启动CMD,它应该可以工作。

#7


5  

If you're getting this error through a service account like Visual Studio TFS Build controller service or any other background service, make sure you restart the service after installing npm as the new PATH environment settings will not be picked up by those already running processes. I was getting same error through my build service but I had npm installed and running in the console.

如果您通过Visual Studio TFS Build controller服务或任何其他后台服务等服务帐户获得此错误,请确保在安装了npm之后重新启动服务,因为新的路径环境设置不会被已经运行的进程接收。我在构建服务中遇到了相同的错误,但是我在控制台安装并运行npm。

#8


4  

For windows users: A picture tells thousand words “npm”不能识别为内部或外部命令、可操作程序或批处理文件

对于windows用户来说:一张图片可以显示上千个单词

Refrence: "npm not recognized as internal or external command

折射:“npm不被识别为内部或外部命令

#9


3  

Had the same problem on Windows 8.1 64 bit.
Turns out i get that problem if I start cmd by typing it in the path bar at the top of a folder window
or
when i shift right click in a folder window and then open command prompt from the list.

When I run cmd using Run or Just from the cmd.exe executable it works.

在Windows 8.1的64位上也有同样的问题。如果我在一个文件夹窗口的顶部的路径栏中键入它,或者当我在一个文件夹窗口中右键点击,然后从列表中打开命令提示符,我就会得到这个问题。当我运行cmd时用run或者直接从cmd。exe可执行它的工作原理。

#10


2  

I installed nodejs following this AngularJS tutorial. the npm command did work when I open a new cmd window but not in the current one.
So the fix was to close and open a new cmd window.

我在这个AngularJS教程之后安装了nodejs。当我打开一个新的cmd窗口时,npm命令确实有效,但在当前窗口中无效。因此,解决方案是关闭并打开一个新的cmd窗口。

#11


2  

You might have got an answer but this might help others since I experienced the same issue recently and this is what I did:

你可能得到了一个答案,但这可能会帮助其他人,因为我最近经历了同样的问题,这就是我所做的:

  1. Provided a path entry to powershell. For me the path was C:\Windows\System32\WindowsPowerShell\v1.0
  2. 提供了进入powershell的路径。对我来说的路径是C:\Windows\System32\ WindowsPowerShell \ v1.0
  3. Then I opened cmd prompt with administrative privileges and copied this

    然后,我使用管理特权打开cmd提示符并复制它。

    @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

    @powershell -NoProfile -ExecutionPolicy unrestricted -命令“iex ((new object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1’)”铺好道路路径= % & & %,% ALLUSERSPROFILE % \巧克力色\ bin

into the cmd prompt.

cmd提示。

  1. Next, choco install nodejs
  2. 接下来,安装nodejs乔科省
  3. Restart and everything worked fine. Try opening cmd without admin privileges and run npm -v Cheers.
  4. 重新启动,一切工作正常。尝试在没有管理员权限的情况下打开cmd,运行npm -v的欢呼。

#12


2  

I ran into this problem the other day on my Windows 7 machine. Problem wasn't my path, but I had to use escaped forward slashes instead of backslashes like this:

前几天我在Windows 7上遇到了这个问题。问题不是我的路,但我必须使用转义前斜杠而不是像这样的反斜杠:

"scripts": {
    "script": ".\\bin\\script.sh"
}

#13


2  

If the package is successfully installed and still shows the message "'npm' is not recognized as an internal or external command, operable program or batch file."

如果软件包成功安装并且仍然显示“'npm'不被识别为内部或外部命令、可操作程序或批处理文件”。

  1. Click windows start button.
  2. 点击windows开始按钮。
  3. Look for "ALL APPS", you will see Node.js and Node.js Command prompt there.
  4. 寻找“所有应用”,你会看到Node。js和节点。js命令提示符。
  5. You can run the Node.js Command prompt as administrator and soon as its run it will show the message "Your environment has been set up for using Node.js 6.3.0 (x64) and npm."
  6. 可以运行节点。作为管理员的js命令提示符,运行后会显示“您的环境已经设置为使用Node”。js 6.3.0 (x64)和npm "

and then it works from there...

然后它在那里工作…

#14


2  

I ran into this issue as well. It turns out Windows doesn't enjoy single quotes on the command line. The culprit was one of my npm scripts. I changed the single quotes to escaped double quotes:

我也遇到了这个问题。结果是Windows不喜欢命令行中的单引号。罪魁祸首是我的npm脚本之一。我将单引号改为转义双引号:

'npm -s run sass-build'

to

\"npm -s run sass-build\"

#15


1  

I installed Node.js and while trying to install Ionic and cordova using this piece of code:

我安装的节点。在尝试安装Ionic和cordova时,使用以下代码:

npm install -g cordova ionic

安装-g cordova

I faced the above error. I added 'C:\Program Files\nodejs' to my Environment Variable 'PATH'. But still was unable to get over this issue. Turned out that my PATH variable was longer than 2048 characters and so I was unable to add the Nodejs path to it. I had to remove the path of another program and add the Nodejs path. Close and reopen the cmd prompt and try to install Ionic again. This worked for me.

我面对上述错误。我将'C:\程序文件\nodejs'添加到环境变量'PATH'中。但还是无法克服这个问题。原来我的PATH变量的长度超过了2048个字符,所以我无法向它添加Nodejs路径。我必须删除另一个程序的路径并添加Nodejs路径。关闭并重新打开cmd提示符并尝试再次安装Ionic。这为我工作。

#16


1  

I'm updating this thread with a new answer because I've found the solution to my miserable situation after not less than a week ...

我更新了这个帖子并给出了一个新的答案,因为我在不到一周的时间里找到了解决我痛苦处境的办法……

For those still experiencing the error even though they have their path value set properly, check your pathext variable to have the value (default value in windows 7 +) : .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

对于那些仍在经历错误的人,即使他们的路径值设置正确,也要检查你的pathext变量是否有这个值(windows 7 +的默认值):

Mine was to set only to : .BAT and changing it solved the problem. I wonder why nobody brought this up ...

我的答案是:. bat并改变它就解决了问题。我想知道为什么没人提起这个…

Hope this helps!

希望这可以帮助!

#17


0  

For windows8 right click my pc properties then click environment variables user variable or System variables >> new >> put variable name and path : like this C:\Program Files\nodejs Then ok now open cmd and type npm it will work

windows8右键点击我的电脑属性然后点击环境变量用户变量和系统变量> > new > >把变量名和路径:这样C:\Program Files\nodejs然后现在打开cmd和npm型工作

#18


-2  

We need to install nodejs and nothing else do we need to do and then simply use command prompt and change directory to the project in which you want to install npm and then use npm install command. It has worked for me.

我们需要安装nodejs,而不需要做其他事情,然后只需使用命令提示符并将目录更改为要安装npm的项目,然后使用npm安装命令。它对我起了作用。

#1


209  

Just add:

添加:

;C:\Program Files\nodejs\

To the end of your Path variable on the "User variable" section of the Environment Variables on the System Properties.

在系统属性上的环境变量的“用户变量”部分的路径变量的末尾。

After that, reopen your command prompt and type

然后,重新打开命令提示符并输入

npm

This should work.

这应该工作。

#2


56  

Don't forget to reboot your computer after installing node! That one got me.

安装node后不要忘记重新启动您的计算机!一个让我。

#3


14  

To elaborate on Breno's answer... For Windows 7 these steps worked for me:

详细阐述布里诺的回答……对于Windows 7,这些步骤对我起了作用:

  1. Open the Control Panel (Click the Start button, then click Control Panel)
  2. 打开控制面板(单击“开始”按钮,然后单击“控制面板”)
  3. Click User Accounts
  4. 单击用户帐户
  5. Click Change my environment variables
  6. 单击“更改环境变量”
  7. Select PATH and click the Edit... button
  8. 选择路径并点击编辑…按钮
  9. At the end of the Variable value, add ;C:\Program Files\nodejs
  10. 在变量值的末尾,添加;C:\程序文件\nodejs
  11. Click Ok on the "Edit User Variable" window, then click Ok on the "Environment Variables" window
  12. 在“编辑用户变量”窗口上单击Ok,然后在“环境变量”窗口上单击Ok
  13. Start a command prompt window (Start button, then type cmd into the search and hit enter)
  14. 启动命令提示窗口(启动按钮,然后输入cmd到搜索并按回车键)
  15. At the prompt (C:\>) type npm and hit enter; you should now see some help text (Usage: npm <command> etc.) rather than "npm is not recognized..."
  16. 在提示符(C:\>)输入npm,点击回车;您现在应该看到一些帮助文本(使用:npm 等),而不是“npm不被识别……”

Now you can start using npm!

现在你可以开始使用npm了!

#4


9  

I had the same problem described by Ashu, but in addition to that, the PATH entry for nodejs was terminated by a backslash:

我遇到了Ashu所描述的相同问题,但除此之外,nodejs的路径条目被反斜杠终止:

C:\Program Files\nodejs\

I also had to remove that final backslash in order to have it work.

我还必须删除最后的反斜杠才能让它工作。

#5


8  

Don't forget to run cmd as admin.

不要忘记管理cmd。

#6


8  

I faced the exact same issue and notice that after installing node.js there was a new path entry in the user variable section for PATH with value --> c:\User\\AppData\Roaming\npm. Also the Path entry in the system variable is appended with --> C:\Program Files\nodejs. Now since user variable has preference over system you have two options to fix this. Either delete the path from user variable or correct the right path (C:\Program Files\nodejs). Restart CMD and it should work.

我也遇到了同样的问题,在安装node之后注意到了这一点。在带有值的路径的用户变量部分有一个新的路径条目——> c:\用户\应用程序数据\漫游\npm。也进入系统变量的路径- - > C:\Program Files\nodejs.附加既然用户变量对系统有偏好,有两个选项可以解决这个问题。从用户变量中删除路径,或者纠正正确的路径(C:\程序文件\nodejs)。重新启动CMD,它应该可以工作。

#7


5  

If you're getting this error through a service account like Visual Studio TFS Build controller service or any other background service, make sure you restart the service after installing npm as the new PATH environment settings will not be picked up by those already running processes. I was getting same error through my build service but I had npm installed and running in the console.

如果您通过Visual Studio TFS Build controller服务或任何其他后台服务等服务帐户获得此错误,请确保在安装了npm之后重新启动服务,因为新的路径环境设置不会被已经运行的进程接收。我在构建服务中遇到了相同的错误,但是我在控制台安装并运行npm。

#8


4  

For windows users: A picture tells thousand words “npm”不能识别为内部或外部命令、可操作程序或批处理文件

对于windows用户来说:一张图片可以显示上千个单词

Refrence: "npm not recognized as internal or external command

折射:“npm不被识别为内部或外部命令

#9


3  

Had the same problem on Windows 8.1 64 bit.
Turns out i get that problem if I start cmd by typing it in the path bar at the top of a folder window
or
when i shift right click in a folder window and then open command prompt from the list.

When I run cmd using Run or Just from the cmd.exe executable it works.

在Windows 8.1的64位上也有同样的问题。如果我在一个文件夹窗口的顶部的路径栏中键入它,或者当我在一个文件夹窗口中右键点击,然后从列表中打开命令提示符,我就会得到这个问题。当我运行cmd时用run或者直接从cmd。exe可执行它的工作原理。

#10


2  

I installed nodejs following this AngularJS tutorial. the npm command did work when I open a new cmd window but not in the current one.
So the fix was to close and open a new cmd window.

我在这个AngularJS教程之后安装了nodejs。当我打开一个新的cmd窗口时,npm命令确实有效,但在当前窗口中无效。因此,解决方案是关闭并打开一个新的cmd窗口。

#11


2  

You might have got an answer but this might help others since I experienced the same issue recently and this is what I did:

你可能得到了一个答案,但这可能会帮助其他人,因为我最近经历了同样的问题,这就是我所做的:

  1. Provided a path entry to powershell. For me the path was C:\Windows\System32\WindowsPowerShell\v1.0
  2. 提供了进入powershell的路径。对我来说的路径是C:\Windows\System32\ WindowsPowerShell \ v1.0
  3. Then I opened cmd prompt with administrative privileges and copied this

    然后,我使用管理特权打开cmd提示符并复制它。

    @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin

    @powershell -NoProfile -ExecutionPolicy unrestricted -命令“iex ((new object net.webclient).DownloadString(‘https://chocolatey.org/install.ps1’)”铺好道路路径= % & & %,% ALLUSERSPROFILE % \巧克力色\ bin

into the cmd prompt.

cmd提示。

  1. Next, choco install nodejs
  2. 接下来,安装nodejs乔科省
  3. Restart and everything worked fine. Try opening cmd without admin privileges and run npm -v Cheers.
  4. 重新启动,一切工作正常。尝试在没有管理员权限的情况下打开cmd,运行npm -v的欢呼。

#12


2  

I ran into this problem the other day on my Windows 7 machine. Problem wasn't my path, but I had to use escaped forward slashes instead of backslashes like this:

前几天我在Windows 7上遇到了这个问题。问题不是我的路,但我必须使用转义前斜杠而不是像这样的反斜杠:

"scripts": {
    "script": ".\\bin\\script.sh"
}

#13


2  

If the package is successfully installed and still shows the message "'npm' is not recognized as an internal or external command, operable program or batch file."

如果软件包成功安装并且仍然显示“'npm'不被识别为内部或外部命令、可操作程序或批处理文件”。

  1. Click windows start button.
  2. 点击windows开始按钮。
  3. Look for "ALL APPS", you will see Node.js and Node.js Command prompt there.
  4. 寻找“所有应用”,你会看到Node。js和节点。js命令提示符。
  5. You can run the Node.js Command prompt as administrator and soon as its run it will show the message "Your environment has been set up for using Node.js 6.3.0 (x64) and npm."
  6. 可以运行节点。作为管理员的js命令提示符,运行后会显示“您的环境已经设置为使用Node”。js 6.3.0 (x64)和npm "

and then it works from there...

然后它在那里工作…

#14


2  

I ran into this issue as well. It turns out Windows doesn't enjoy single quotes on the command line. The culprit was one of my npm scripts. I changed the single quotes to escaped double quotes:

我也遇到了这个问题。结果是Windows不喜欢命令行中的单引号。罪魁祸首是我的npm脚本之一。我将单引号改为转义双引号:

'npm -s run sass-build'

to

\"npm -s run sass-build\"

#15


1  

I installed Node.js and while trying to install Ionic and cordova using this piece of code:

我安装的节点。在尝试安装Ionic和cordova时,使用以下代码:

npm install -g cordova ionic

安装-g cordova

I faced the above error. I added 'C:\Program Files\nodejs' to my Environment Variable 'PATH'. But still was unable to get over this issue. Turned out that my PATH variable was longer than 2048 characters and so I was unable to add the Nodejs path to it. I had to remove the path of another program and add the Nodejs path. Close and reopen the cmd prompt and try to install Ionic again. This worked for me.

我面对上述错误。我将'C:\程序文件\nodejs'添加到环境变量'PATH'中。但还是无法克服这个问题。原来我的PATH变量的长度超过了2048个字符,所以我无法向它添加Nodejs路径。我必须删除另一个程序的路径并添加Nodejs路径。关闭并重新打开cmd提示符并尝试再次安装Ionic。这为我工作。

#16


1  

I'm updating this thread with a new answer because I've found the solution to my miserable situation after not less than a week ...

我更新了这个帖子并给出了一个新的答案,因为我在不到一周的时间里找到了解决我痛苦处境的办法……

For those still experiencing the error even though they have their path value set properly, check your pathext variable to have the value (default value in windows 7 +) : .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

对于那些仍在经历错误的人,即使他们的路径值设置正确,也要检查你的pathext变量是否有这个值(windows 7 +的默认值):

Mine was to set only to : .BAT and changing it solved the problem. I wonder why nobody brought this up ...

我的答案是:. bat并改变它就解决了问题。我想知道为什么没人提起这个…

Hope this helps!

希望这可以帮助!

#17


0  

For windows8 right click my pc properties then click environment variables user variable or System variables >> new >> put variable name and path : like this C:\Program Files\nodejs Then ok now open cmd and type npm it will work

windows8右键点击我的电脑属性然后点击环境变量用户变量和系统变量> > new > >把变量名和路径:这样C:\Program Files\nodejs然后现在打开cmd和npm型工作

#18


-2  

We need to install nodejs and nothing else do we need to do and then simply use command prompt and change directory to the project in which you want to install npm and then use npm install command. It has worked for me.

我们需要安装nodejs,而不需要做其他事情,然后只需使用命令提示符并将目录更改为要安装npm的项目,然后使用npm安装命令。它对我起了作用。