简体   繁体   English

npm挂起任何命令

[英]npm hangs on any command

I installed last version of Node.js (12.2 x64 windows) After I run cmd as administrator and try to call any npm command (except npm -v ), cmd window is hanging. 我安装了最新版本的Node.js(12.2 x64 windows)以管理员身份运行cmd并尝试调用任何npm命令( npm -v除外),cmd窗口挂起。 After Ctrl + C it returns Ctrl + C之后它返回

 Terminate batch job (Y/N)? 

在此输入图像描述

I was trying to left cmd for several hours but it didn't give some results. 我试图离开cmd几个小时,但没有给出一些结果。 It is strange because node.exe process is consuming CPU and memory quite hard. 这很奇怪,因为node.exe进程很难消耗CPU和内存。

I was trying to reinstall node.js several times without success. 我试图多次重新安装node.js但没有成功。
I can't even get some debug information. 我甚至无法获得一些调试信息。

I faced such issue on my VM which I was using by connecting via rdp. 我通过rdp连接我在VM上遇到了这样的问题。 Same version installed on my laptop works ok. 在我的笔记本电脑上安装的相同版本正常 On my VM I had Kaspersky antivirus, but after switching it off I got same result. 在我的VM上我有卡巴斯基防病毒软件,但在关闭它之后我得到了相同的结果。

Did somebody face such issue? 有人面对这样的问题吗? Is there some way to get more information problem? 有没有办法获得更多的信息问题? Could you please recommend me some way to resolve? 能否请你推荐一些解决方法?

I've finally resolved my issue. 我终于解决了我的问题。 According to suggestion from our local read me file 根据我们当地的阅读文件的建议

Node.js (with NPM) Note: On windows server machines, instead of node modules been installed at user %APPDATA% path, its better to install at a global path eg c:\\npm. Node.js(使用NPM)注意:在Windows服务器计算机上,而不是在用户%APPDATA%路径上安装节点模块,最好安装在全局路径上,例如c:\\ npm。 This could be acheived by the npm command: $ npm config set prefix 'c:\\npm' This is not required on individual developer's machine. 这可以通过npm命令实现:$ npm config set prefix'c:\\ npm'这在个别开发人员的机器上不是必需的。

I've executed npm config set prefix 'c:\\npm' . 我已经执行了npm config set prefix 'c:\\npm'

As result it added prefix="'c:\\\\npm'" to my .npmrc file 结果它在我的.npmrc文件中添加了prefix="'c:\\\\npm'"

This make node.js really crazy. 这使得node.js真的很疯狂。 It takes me about an hour to debug all these js scripts npm.js code.js etc... to find that it calls mkdirp with 'c:\\\\npm'\\etc and it loop process forever. 我花了大约一个小时来调试所有这些js脚本npm.js code.js等...发现它用'c:\\\\npm'\\etc调用mkdirp并且它永远循环进程。

If anyone will encounter this problem in the future you need to find the npmrc file delete it and delete all configurations for node, delete node as well and install it, this should fix that. 如果将来有人会遇到这个问题你需要找到npmrc文件删除它并删除节点的所有配置,删除节点并安装它,这应该解决这个问题。 when deleting node some of the configurations aren't deleted so you have to delete it manually. 删除节点时,某些配置不会被删除,因此您必须手动删除它。

It happenned for me too : I installed node only for my user on Windows 10, and managed to use npm by calling it using the full path "c:\\Program Files\\nodejs\\npm" 它也适用于我:我在Windows 10上仅为我的用户安装了节点,并通过使用完整路径"c:\\Program Files\\nodejs\\npm"调用它来设法使用npm

I solved by using "c:\\Program Files\\nodejs\\npm" config set prefix "c:\\Program Files\\nodejs" (setting the prefix to the full path to npm) 我解决了使用"c:\\Program Files\\nodejs\\npm" config set prefix "c:\\Program Files\\nodejs" (将前缀设置为npm的完整路径)

And the result was : 结果是:

    λ cat c:\Users\<my_user_name>\.npmrc
    prefix=c:\Program Files\nodejs

Now eveything works fine. 现在eveything工作正常。

It's if the prefix is not set correctly. 如果未正确设置前缀。

Just want to point out to those commenting -if you can't get access to the command line npm, then you can't run npm config , obviously. 只想指出那些评论 - 如果你无法访问命令行npm,那么显然你无法运行npm config

Open up powershell and type notepad $HOME/.npmrc , and edit the line where it says prefix=... and change it to a valid one. 打开notepad $HOME/.npmrc并键入notepad $HOME/.npmrc ,并编辑其中的prefix=...的行,并将其更改为有效的行。

For clarity, when you call: 为清楚起见,当您致电时:

npm config set prefix 'c:\npm'

you are required to have the ' wrapping the path, but you need to remove them from the .npmrc file so that npm commands will work. 你需要有'包装路径,但你需要从.npmrc文件中删除它们,以便npm命令可以工作。 So your resulting line in .npmrc file should look like: 因此,.npmrc文件中的结果行应如下所示:

prefix="c:\\npm"

只需删除User /%UserProfile%上的.nprmc文件,现在尝试命令,如果它甚至重新安装一次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM