love
V2EX  ›  Node.js

npm 安装时下载 github 内容下载不动,用代理的话就不能用国内源了,这事不能两全吗?

  •  
  •   love · Jul 31, 2020 · 4587 views
  •   You need to sign in to view this topic
    This topic created in 2303 days ago, the information mentioned may be changed or developed.
    因为 npm 的设计原因,安装个东西会生产成千上万的 http 请求,用代理的速度不是太理想,所以我用了国内淘宝源。但项目用了几个包安装时需要从 github 下东西,而你知道的那是完全下不动的。

    那问题就来了,设置了 npm proxy 的话连国内源的请求也被代理了,是不是有我不知道的方式可以解决这个问题?
    7 replies  •  2024-06-11 16:14:20 +08:00
    maoxs2
    maoxs2
    Aug 1, 2020 via Android
    1
    一般需要 github 下东西的库都支持通过环境变量选择本地已下载的文件或者通过环境变量自定义镜像网址(要是没有就提 issue
    flyingfz
    flyingfz
    Aug 1, 2020
    2
    一般而言, 需要从 github 下的东西, 这些包 应该会有环境变量可以设置镜像地址,一般而言, 这些在阿里镜像里也有。

    当然, 上面提到的“一般而言”, 指的是 比较常用的包。 例如 前端经常用到的 node-sass , 还有 puppeteer 之类。
    love
    love
    OP
    Aug 1, 2020
    4
    @flyingfz 对就是这个。

    这么看 node 没有一个“标准"的代理环境变量处理这种,http_proxy 连 registry 请求也代理了,没有人提 bug 报告吗
    winzkh
    winzkh
    Aug 9, 2020
    5
    反代 github
    wisetc
    wisetc
    Aug 30, 2020 via iPhone
    6
    可以用缓存镜像,拉过一次之后就不用再找 upurl 了,不知道有没有这种方案。
    ddllzz
    ddllzz
    Jun 11, 2024
    7
    抱歉挖一下坟,我遇到的库不是“一般而言”的库:git://github.com/adobe-webplatform/eve.git

    我目前的解决方案是:

    npm install 前执行

    ```
    git config --global url."https://sciproxy.com/https://github.com/".insteadOf "git://github.com/"
    ```

    安装完之后,要恢复的话

    ```
    git config --global --unset url."https://sciproxy.com/https://github.com/".insteadOf "git://github.com/"
    ```

    对于“一般而言”的库,可以看看: https://help.aliyun.com/document_detail/202442.html?spm=5176.smartservice_service_create_ticket_step_2.help.dexternal.70033f1bwPqkm6&spm#section-3rm-wmg-l27
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   3856 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 05:41 · PVG 13:41 · LAX 21:41 · JFK 00:41
    ♥ Do have faith in what you're doing.