解决pnpm安装报错:node_modules/gifsicle postinstall$ node lib/install.js

8,497 阅读1分钟

遇到问题

最近在使用 pnpm 安装依赖时遇到了报错,死活都下载不下来。 pnpm add xxx 或者 pnpm i

都报错如下:
.../node_modules/gifsicle postinstall$ node lib/install.js

image.png

删除node-modules包、重新 installcnpm i 也是不行!

查资料学习后发现问题原因,得以解决,谨以此篇记录自己工作中的踩坑之路。

报错原因

安装某个包时,内部需要这个依赖包,其中部分依赖包需要从GitHub上下载,而GitHub的资源库DNS有问题,导致这些依赖包无法安装而报错!

解决方案

  • 命令后加参数 --ignore-scripts 忽略scripts相关依赖

如果下载指定依赖: pnpm i xxx --ignore-scripts

如果卸载不掉的情况,可以先去package.json文件中手动删除要删的依赖,保存;然后: pnpm i --ignore-scripts

成功解决: image.png

  • 修改host文件
    在本地host文件中添加以下内容:
    (windows下,host文件路径:C:\Windows\System32\drivers\etc )

     52.74.223.119     github.com
     192.30.253.119    gist.github.com
     54.169.195.247    api.github.com
     185.199.111.153   assets-cdn.github.com
     151.101.76.133    raw.githubusercontent.com
     151.101.76.133    gist.githubusercontent.com
     151.101.76.133    cloud.githubusercontent.com
     151.101.76.133    camo.githubusercontent.com
     151.101.76.133    avatars0.githubusercontent.com
     151.101.76.133    avatars1.githubusercontent.com
     151.101.76.133    avatars2.githubusercontent.com
     151.101.76.133    avatars3.githubusercontent.com
     151.101.76.133    avatars4.githubusercontent.com
     151.101.76.133    avatars5.githubusercontent.com
     151.101.76.133    avatars6.githubusercontent.com
     151.101.76.133    avatars7.githubusercontent.com
     151.101.76.133    avatars8.githubusercontent.com
    

    重新 pnpm i 就可以了