简体   繁体   English

npm 在 Windows 10 上非常慢

[英]npm is very slow on Windows 10

This question is basically a duplicate of this one , except that the accepted answer on that question was, "it's not actually slower, you just weren't running the timing command correctly."这个问题基本上是重复的这一个,除了对这个问题进行接受的回答是,“这不是真正慢,你只是没有正确运行定时指令。”

In my case, it actually is slower!就我而言,它实际上更慢! :) :)

I'm on Windows 10. Here's the output from PowerShell's Measure-Command (the TotalMilliseconds line represents wall-clock time):我使用的是 Windows 10。这是 PowerShell 的 Measure-Command 的输出(TotalMilliseconds 行代表挂钟时间):

PS> Measure-Command {npm --version}

Days              : 0
Hours             : 0
Minutes           : 0
Seconds           : 1
Milliseconds      : 481
Ticks             : 14815261
TotalDays         : 1.71472928240741E-05
TotalHours        : 0.000411535027777778
TotalMinutes      : 0.0246921016666667
TotalSeconds      : 1.4815261
TotalMilliseconds : 1481.5261

A few other numbers, for comparison:其他一些数字,用于比较:

  • '{.\\node_modules.bin\\mocha}': 1300ms '{.\\node_modules.bin\\mocha}':1300 毫秒
  • 'npm run test' (just runs mocha): 3300ms 'npm run test'(只运行 mocha):3300 毫秒
  • npm help : 1900ms. npm help :1900 毫秒。
  • the node interpreter itself is ok: node -e 0 : 180ms节点解释器本身没问题: node -e 0 : 180ms

It's not just npm that's slow... mocha reports that my tests only take 42ms, but as you can see above, it takes 1300ms for mocha to run those 42ms of tests!不仅仅是 npm 很慢…… mocha 报告说我的测试只需要 42 毫秒,但是正如您在上面看到的,mocha 需要 1300 毫秒来运行那些 42 毫秒的测试!

I've had the same trouble.我也遇到过同样的麻烦。 Do you have Symantec Endpoint Protection?您有赛门铁克端点保护吗? Try disabling Application and Device Control in Change Settings > Client Management > General > Enable Application and Device Control.尝试在更改设置 > 客户端管理 > 常规 > 启用应用程序和设备控制中禁用应用程序和设备控制。

(You could disable SEP altogether; for me the command is: "%ProgramFiles(x86)%\\Symantec\\Symantec Endpoint Protection\\smc.exe" -stop .) (您可以完全禁用 SEP;对我而言,命令是: "%ProgramFiles(x86)%\\Symantec\\Symantec Endpoint Protection\\smc.exe" -stop 。)

If you have some other anti-virus, there's likely a way to disable it as well.如果您有其他一些防病毒软件,也可能有一种方法可以禁用它。 Note that closing the app in the Notification area might not stop the virus protection.请注意,在通知区域关闭应用程序可能不会停止病毒防护。 The problem is likely with any kind of realtime protection that scans a process as it starts.任何一种在进程启动时对其进行扫描的实时保护都可能存在问题。 Since node and git are frequently-invoked short-running processes, this delay is much more noticeable.由于 node 和 git 是频繁调用的短期运行进程,因此这种延迟更加明显。
In Powershell, I like to measure the performance of git status, both before and after that change: Measure-Command { git status }在 Powershell 中,我喜欢测量 git status 在更改前后的性能: Measure-Command { git status }

I ran into this problem long ago, I think it was an extension that I had.我很久以前就遇到过这个问题,我认为这是我的一个扩展。 I use Visual Studio Code, and when it has no extensions and running bash:我使用 Visual Studio Code,当它没有扩展并运行 bash 时:

//GIT Bash Configuration
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",

it actually flies, I use both OS, so I can tell the difference.它实际上飞起来了,我同时使用两个操作系统,所以我可以分辨出不同之处。 Try using different tools and disabling some.尝试使用不同的工具并禁用一些工具。

And if that still doesn't work, check your antivirus, maybe it's slowing down the process?如果这仍然不起作用,请检查您的防病毒软件,也许它会减慢进程?

Been googling this all day, with no luck.一整天都在谷歌上搜索,没有运气。 Decided to uninstall Java to see what would happen and bingo, solved my problem.决定卸载 Java 看看会发生什么和宾果游戏,解决了我的问题。 I know this is an old thread, but I found myself coming back to it so many times to see if I missed anything.我知道这是一个旧线程,但我发现自己多次回到它,看看我是否错过了什么。

off topic: Got to figure out how to get Java working now 🤦 Didn't know about Measure-Command , so I'll be using that in the future!题外话:现在必须弄清楚如何让 Java 工作 🤦 不知道Measure-Command ,所以我将来会使用它!

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

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