我对nodejs完全不熟悉。我试图让nodejs在我的Windows 2008盒子上工作,以安装Karma,我将用于TDDing我的AngularJs代码。到目前为止,我已经完成了以下步骤

Install using Chocolatey ==> npm is not recognised Install using 64-bit nodejs installer from nodejs.org ==> npm is not recognised At this stage, running where npm gives me c:\User\<Username>\AppData\Roaming\npm which has nothing in it I figure out that nodejs is installed in C:\Program Files\nodejs. Opening a command prompt in this directory makes npm work fine. So I added C:\Program Files\nodejs to PATH only to get the same error again that npm is not recognized 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 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.

在这个过程中,我是否错过了任何重要的步骤?

Edit

我发现如果我从程序文件中打开“Nodejs命令提示符”,那么npm是可以识别的。如何让它在正常的命令提示符下工作?

Edit

在node之后,我开始在另一个应用程序中遇到类似的问题。我在超级用户上发布了这个问题,正如被接受的答案所正确指出的那样,我在我的PATH中有一个额外的引用,这导致了引用后添加的所有路径出现问题。我有一种感觉,一些Chocolatey安装添加了这句令人不安的引用,但我只是不确定是哪一个。


当前回答

在尝试了我在YouTube和stackoverflow上找到的各种解决方案来解决这个问题后,所有的努力都无济于事。

我猜问题一定是因为节点必须已经移动到不同的文件夹而不是<C:\Program Files>所以我所做的是我卸载节点,然后重新安装它,一切恢复正常。

我相信这个过程之后你就会没事的。

其他回答

我知道这个问题很老了,我们有很多答案,不幸的是,我的情况不同,因此有不同的解决方案。

如果在机器中安装节点后才开始使用nvm来管理节点版本,则很可能会面临同样的问题。

我安装了一个10.15.3版本,然后我不得不使用另一个版本,因为我的一个项目有一些紧密的依赖关系。然后我决定安装nvm,在安装时询问我是否需要nvm来管理我机器上已经安装的10.15.3版本。是的,我答应了,希望它能解决这个问题,不幸的是,它没有。

无论我尝试其他答案中提到的许多其他事情,包括设置路径,我总是得到这个错误。最后,为了解决这个问题,我尝试了这些方法。

卸载已安装的节点版本,例如nvm Uninstall 10.15.3 确保没有其他节点版本在那里,nvm列表 然后安装需要的版本,例如nvm install 10.15.3。这将为您提供前面所述的输出。

下载node.js 10.15.3版本(64位)… 完整的 创建C:\Users\ SibeeshVenu \ AppData \ \ nvm \ temp徘徊 下载npm版本6.4.1…完整的 安装npm v6.4.1… 安装完成。如果您想使用这个版本,请键入 NVM使用10.15.3 PS C:\Users\SibeeshVenu> nvm使用10.15.3 现在使用节点v10.15.3(64位)

请注意,从上面的命令中,也安装了npm。 现在使用你需要的版本,nvm使用10.15.3并输入npm

我按照AngularJS教程安装了nodejs。npm命令工作时,我打开一个新的cmd窗口,但不是在当前的。 所以解决办法是关闭并打开一个新的cmd窗口。

你可能已经收到了回复,但这可能会帮助其他人,因为我最近也遇到了同样的问题,这就是我所做的:

Added a path for Powershell. For me, the path was C:\Windows\System32\WindowsPowerShell\v1.0 Then, I opened the command prompt with administrative privileges and ran @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin Next, choco install nodejs Restart and everything worked fine. Try opening the command prompt without admin privileges and run npm -v

欢呼。

有一天,我在自己的Windows 7电脑上遇到了这个问题。问题不在于我的路径,而是我必须使用转义的正斜杠而不是反斜杠,就像这样:

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

在64位的Windows 8.1上也有同样的问题。 事实证明,我得到的问题,如果我开始cmd键入在文件夹窗口顶部的路径栏或当我在文件夹窗口中右键单击,然后从列表打开命令提示符。 当我运行cmd使用运行或只是从cmd.exe可执行文件它的工作。