我对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安装添加了这句令人不安的引用,但我只是不确定是哪一个。


当前回答

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

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不喜欢在命令行上使用单引号。罪魁祸首是我的一个npm脚本。我把单引号改成了转义双引号:

'npm -s run sass-build'

to

\"npm -s run sass-build\"

你只需要把它添加到你的环境变量:

第一步:在搜索栏中写env

或 右键开始按钮->系统->高级系统设置->环境变量…->选择“PATH”

第二步:点击新建按钮,添加如下路径:

C: \ Program Files \ nodejs \

只需从这里下载并安装Node.js https://nodejs.org/en/

如果您运行下载的文件并安装它,它们将自动为您的系统配置

你不再需要任何其他配置,现在你可以在任何地方使用npm命令


如果Nodejs安装成功,仍然显示如下信息:

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

Windows用户请执行以下步骤:

进入我的电脑属性 在窗口左侧栏中单击“高级系统设置”。 现在您有了一个系统属性窗口。单击高级 然后,单击环境变量按钮 现在你有了环境变量窗口:从系统变量,选择路径 点击编辑 在变量值的末尾,添加;C:\Program Files\nodejs\ 注意:如果你在其他驱动器上安装了nodejs,请按此操作。 单击“确定”所有打开的对话框

非常重要的提示:“关闭命令提示符并重新启动” (这非常重要,因为如果您没有重新启动命令提示符,则更改将不会反映出来。)

现在你可以在任何地方使用npm命令

我用一个新的答案更新了这个帖子,因为我在不少于一周的时间里找到了解决我痛苦处境的方法……

对于那些仍然遇到错误,即使他们的路径值设置正确,检查你的paextt变量的值(默认值在windows 7 +): .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC

我只设置为:. bat,改变它就解决了问题。我想知道为什么没有人提起这件事…

希望这能有所帮助!

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

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

欢呼。