Nodejs 双十一买的阿里云 npm install 很慢怎么办

Nodejs 双十一买的阿里云 npm install 很慢怎么办

也已经换淘宝源了啊,可是安装 forever 还是贼慢……

有什么解决思路吗

13 回复

试试 yarn ?

设置下淘宝镜像

用 cnpm

设置了,打了下 verbose,是这样的

npm http request GET https://registry.npm.taobao.org/winston
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"e7db138b0fa322efea92b03edea3815d"
npm http request GET https://registry.npm.taobao.org/mkdirp
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"bdc238adde407214aa0f2663940bd60b"
npm http request GET https://registry.npm.taobao.org/nconf
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"52ea63575501cb90187e7e97718ca8c8"
npm http request GET https://registry.npm.taobao.org/utile
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"9d7fa4482b6418547d3b810830ab4287"
npm http request GET https://registry.npm.taobao.org/cliff
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"78b2ce0cf9dd705f240258f0927b183d"
npm http request GET https://registry.npm.taobao.org/flatiron
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"0cc03afe354fff725fb2adb3317cea96"
npm http request GET https://registry.npm.taobao.org/shush
npm info attempt registry request try #2 at 3:09:02 PM
npm verb etag W/"32788543675e1a7aa4137c6b12347fe0"
npm http request GET https://registry.npm.taobao.org/object-assign
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file
npm info retry will retry, error on last attempt: Error: unexpected end of file

醉了,反而是把源换成官方源解决了……

那就换个海外机子

进来后怎么黑天了?

看下你的机器是不是 t5 机型,如果积分没了,就是会强制 20%基站运行的,这个时候有 2 种方案:
1,开启无性能约束模式,透支积分,甚至会产生一定费用
2,关机攒积分,1 核 2g 应该是最大 144 分,有了积分再继续安装

“也已经换淘宝源了啊”——这个应该速度很快呀,晕倒。

这个主题有问题吧

cnpm+国内镜像

针对Node.js项目中npm install命令执行缓慢的问题,尤其是在阿里云环境下,可以尝试以下几种解决方法:

  1. 更换npm源

    • 使用淘宝npm镜像源,通过命令npm config set registry https://registry.npm.taobao.org/设置。
    • 或者,使用cnpm(淘宝提供的npm镜像),安装命令为npm install -g cnpm --registry=https://registry.npm.taobao.org/,之后使用cnpm install代替npm install
  2. 优化npm配置

    • 增加npm的并发数,通过设置环境变量NPM_CONFIG_CONCURRENCY,例如export NPM_CONFIG_CONCURRENCY=10(Linux/Mac)或set NPM_CONFIG_CONCURRENCY=10(Windows)。
    • 设置缓存的最小使用时间,避免频繁清理缓存,命令为npm install --cache-min=100000000
  3. 检查网络连接

    • 确保网络连接稳定且速度快,因为npm需要从远程仓库下载依赖包。
  4. 使用其他包管理工具

    • 考虑使用Yarn代替npm,Yarn缓存每个下载过的包,再次安装时无需重复下载。
  5. 清除npm缓存

    • 有时候缓存中的数据可能会导致安装过程出现问题,可以尝试运行npm cache clean --force命令来清除npm的缓存。

如果上述方法都无法解决问题,建议进一步检查网络环境或npm的配置。

回到顶部