npm install 下载不下来依赖解决方案

news/2023/12/1 11:49:39 标签: npm

背景

最近在构建 前端自动化部署 的方案中发现了一个问题,就是我在npm install的时候,有时候成功,有时候不成功,而且什么代码也没发生更改,报错也就是那么几个错,所以在此也整理了一下遇到这种情况,应该怎么解决!!!

**最终是通过最后一个方案才解决的问题!!**不过不同人不同种情况,建议都试一下,没准是哪个成功了呢。

报错信息

npm ERR! code 128
npm ERR! Command failed: git clone --depth=1 -q -b release-tui/v1.9.0 ssh://git@github.com/seonim-ryu/Squire.git /root/.npm/_cacache/tmp/git-clone-aefc5152
npm ERR! warning: templates not found in /tmp/pacote-git-template-tmp/git-clone-398b0101
npm ERR! fatal: unable to access 'https://github.com/seonim-ryu/Squire.git/': Failed to connect to github.com port 443 after 127228 ms: Couldn't connect to server
npm ERR! 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-11-18T05_05_09_791Z-debug.log

或者

npm ERR! Error while executing:
npm ERR! /usr/local/bin/git ls-remote -h -t https://github.com/nhn/raphael.git
npm ERR!
npm ERR! fatal: repository 'https://github.com/nhn/raphael.git/' not found
npm ERR!
npm ERR! exited with error code: 128

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/zax/.npm/_logs/2020-11-04T07_35_27_206Z-debug.log

或者

npm ERR! code 128
npm ERR! Command failed: git clone --depth=1 -q -b release-tui/v1.9.0 git://github.com/seonim-ryu/Squire.git /root/.npm/_cacache/tmp/git-clone-c2406dda
npm ERR! warning: templates not found in /tmp/pacote-git-template-tmp/git-clone-b24013c3
npm ERR! fatal: unable to access 'https://github.com/seonim-ryu/Squire.git/': Failure when receiving data from the peer
npm ERR! 

npm ERR! A complete log of this run can be found in:
npm ERR!     /root/.npm/_logs/2023-11-18T05_22_44_186Z-debug.log

解决方案

替换为https

# 在npm install执行之前,输入下面命令
git config --global url."https://".insteadof git://
git config --global url."https://github.com/".insteadOf "ssh://git@github.com/"

采用国内镜像源

  1. 修改成淘宝镜像源

    npm config set registry https://registry.npm.taobao.org
    # 验证命令是否生效
    npm config get registry
    # 如果返回https://registry.npm.taobao.org,说明镜像配置成功。
    
  2. 修改成华为云镜像

    npm config set registry https://mirrors.huaweicloud.com/repository/npm/
    
  3. 修改为腾讯云镜像

    npm config set registry http://mirrors.cloud.tencent.com/npm/
    
  4. 通过使用淘宝的cnpm安装

    npm install -g cnpm --registry=https://registry.npm.taobao.org
    

最后的安装命令

npm install --registry=https://registry.npm.taobao.org

使用CDN加速

git config --global url."https://hub.fgit.cf".insteadOf "https://github.com"

注意:这个是对 https 协议进行代理设置,也就是仅对 git clone https://www.github.com/xxxx/xxxx.git 这种命令有效。对于 SSH 协议,也就是 git clone git@github.com:xxxxxx/xxxxxx.git 这种,依旧是无效的。

使用域名映射

github包下载不下来本质还是因为被墙了,找到可以访问github的DNS,然后修改本地的host文件,直接访问

查询github的DNS 选择一个TTL值最小的ip复制

在这里插入图片描述

然后去/etc/hosts目录下,进行映射

20.205.243.166  github.com

点就是不确定什么时候就又不可以访问了,再去查新的IP替换hosts里面的就可以了

代理

查看是否使用了代理

git config --global --get http.proxy
git config --global --get https.proxy

关闭代理

git config --global --unset http.proxy
git config --global --unset https.proxy

或者开启代理,并校验代理是否正确

git config --global http.proxy http://127.0.0.1:41091
git config --global https.proxy http://127.0.0.1:41091

特殊依赖设置

我本次项目没下载下来的原因是因为 tui-editor组件,在这里面修改一些配置,即可下载下来

1、修改package.json文件

将 “tui-editor”: “1.3.3” 替换成 “@toast-ui/editor”: “^3.1.3”,

2、找到 src/components/MarkdownEditor/index.vue 文件修改代码

1.import ‘tui-editor/dist/tui-editor.css’ 替换成 import ‘@toast-ui/editor/dist/toastui-editor.css’

2.import Editor from ‘tui-editor’ 替换成 import Editor from ‘@toast-ui/editor’

3.删除 import ‘tui-editor/dist/tui-editor-contents.css’

4.将所有 editor.getValue 替换成 editor.getMarkdown

5.将所有 editor.setValue 替换成 editor.setMarkdown

6.将 editor.getHtml 替换成 editor.getHTML
\7. 将 editor.remove() 替换成 editor.destroy()

3.找到 src/components/MarkdownEditor/default-options.js文件修改代码

toolbarItems: [
‘heading’,‘bold’,‘italic’,‘strike’,‘divider’,
‘hr’,‘quote’,‘divider’,
‘ul’,‘ol’,‘task’,‘indent’,‘outdent’,‘divider’,
‘table’,‘image’,‘link’,‘divider’,
‘code’,‘codeblock’
]
替换成
toolbarItems: [
[‘heading’, ‘bold’, ‘italic’, ‘strike’],
[‘hr’, ‘quote’],
[‘ul’, ‘ol’, ‘task’, ‘indent’, ‘outdent’],
[‘table’, ‘image’, ‘link’],
[‘code’, ‘codeblock’]
]

参考:npm install失败的分析与解决方案,以及修复完成的代码地址

终极方案

在报错信息提示下载不下来的包执行以下命令

比如报错信息上有两个包seonim-ryu/Squire.git/nhn/raphael.git/,而且报错信息都跟git ls-remote -h -t xxx有关,那么咱们就单独找到这些包的国内镜像地址,并用镜像地址执行该命令

如下:

git config --global url.'https://hub.fgit.cf/nhn/raphael.git'.insteadOf 'https://github.com/nhn/raphael.git'
git config --global url.'https://hub.fgit.cf/seonim-ryu/Squire.git'.insteadOf 'git://github.com/seonim-ryu/Squire.git'
git config --global url.'https://hub.fgit.cf/adobe-webplatform/eve.git'.insteadOf 'git://github.com/adobe-webplatform/eve.git'
git ls-remote -h -t https://hub.fgit.cf/nhn/raphael.git
git ls-remote -h -t https://hub.fgit.cf/seonim-ryu/Squire.git

参考:安装依赖时错误:fatal: repository ‘https://github.com/nhn/raphael.git/’ not found · Issue #3491 · PanJiaChen/vue-element-admin

其中,镜像地址可以安装油猴插件,然后搜索:Github 增强 - 高速下载

最终是采用该方案来解决的问题!!!!!!


http://www.niftyadmin.cn/n/5198855.html

相关文章

归并排序知识总结

归并排序思维导图: 知识点:如果原序列中两个数的值是相同的,它们在排完序后,它们的位置不发生变化,那么这个排序是稳定的。快速排序是不稳定的,归并排序是稳定的。 快排变成稳定的>使快排排序数组中的每…

服务器探针-serverstatus

{alert type"info"} 之前给大家介绍过一个简单的服务器监控。uptime-kuma 今天给各位带来一个酷炫的多服务器探针和多服务器监控。ServerStatus {/alert} 作者的开源项目地址如下:https://github.com/cppla/ServerStatus 作者的项目体验地址如下 https://…

以“防方视角”观Shiro反序列化漏洞

为方便您的阅读,可点击下方蓝色字体,进行跳转↓↓↓ 01 案例概述02 攻击路径03 防方思路 01 案例概述 这篇文章来自微信公众号“潇湘信安”,记录的某师傅如何发现、利用Shiro反序列化漏洞,又是怎样绕过火绒安全防护实现文件落地、…

机器学习介绍与分类

随着科学技术的不断发展,机器学习作为人工智能领域的重要分支,正逐渐引起广泛的关注和应用。本文将介绍机器学习的基本概念、原理和分类方法,帮助读者更好地理解和应用机器学习技术。 一、机器学习的基本概念 机器学习是一种通过从数据中学…

数据仓库_模型设计_学习目录

前言: 1、问什么要写这篇博客? 随着自己在数仓岗位工作的年限增加,对数仓的理解和认知也在发生着变化 所有用这篇博客来记录工作中用到的知识点与经验 2、这篇博客主要记录了那些内容? 主要会记录一些数仓建设方法论和工作技巧 目…

目标检测YOLO系列从入门到精通技术详解100篇-【目标检测】3D视觉

目录 知识储备 液态透镜 发展过程 工作原理 应用 算法原理 3D相机的工作原理

【洛谷 P3743】kotori的设备 题解(二分答案+循环)

kotori的设备 题目背景 kotori 有 n n n 个可同时使用的设备。 题目描述 第 i i i 个设备每秒消耗 a i a_i ai​ 个单位能量。能量的使用是连续的,也就是说能量不是某时刻突然消耗的,而是匀速消耗。也就是说,对于任意实数,…

常见的面试算法题:阶乘、回文、斐波那契数列

1.阶乘算法 Factorial 例如:给出数字5,对其以下的的每个数字相乘,结果等于120 解:递归 Recursive function factorial(n) {// 如果n为0或1,阶乘是1if (n 0 || n 1) {return 1;}// 否则,返回n乘以n-1的…

Linux本地WBO创作白板部署与远程访问

文章目录 前言1. 部署WBO白板2. 本地访问WBO白板3. Linux 安装cpolar4. 配置WBO公网访问地址5. 公网远程访问WBO白板6. 固定WBO白板公网地址 前言 WBO在线协作白板是一个自由和开源的在线协作白板,允许多个用户同时在一个虚拟的大型白板上画图。该白板对所有线上用…

MacOS - Cpolar 在 Mac 上如何使用?

1、下载并配置环境变量 brew tap probezy/core && brew install cpolar 2、 Token 认证 cpolar authtoken xxx 3、安装服务 sudo cpolar service install 4、启动服务 sudo cpolar service start 5、创建隧道 访问地址:http://127.0.0.1:9200&…

python连接hive报错:TypeError: can‘t concat str to bytes

目录 一、完整报错 二、解决 三、 其他报错 一、完整报错 Traceback (most recent call last): File "D:/Gitlab/my_world/hive2csv.py", line 18, in <module> conn hive.Connection(hosthost, portport, usernameusername, passwordpassword, data…

享元模式学习

背景 享元模式(Flyweight Pattern)&#xff1a;运用共享技术有效地支持大量细粒度对象的复用。系统只使用少量的对象&#xff0c;而这些对象都很相似&#xff0c;状态变化很小&#xff0c;可以实现对象的多次复用。由于享元模式要求能够共享的对象必须是细粒度对象&#xff0c…

JVM对象创建与内存分配

对象的创建 对象创建的主要流程&#xff1a; 类加载推荐博客&#xff1a;JVM类加载机制详解 类加载检查 虚拟机遇到一条new指令时&#xff0c;首先将去检查这个指令的参数是否能在常量池中定位到一个类的符号引用&#xff0c;并且检查这个符号引用代表的类是否已被加载、解析…

leetcode做题笔记242. 有效的字母异位词

给定两个字符串 s 和 t &#xff0c;编写一个函数来判断 t 是否是 s 的字母异位词。 注意&#xff1a;若 s 和 t 中每个字符出现的次数都相同&#xff0c;则称 s 和 t 互为字母异位词。 示例 1: 输入: s "anagram", t "nagaram" 输出: true示例 2: 输…

vue和uni-app的递归组件排坑

有这样一个数组数据&#xff0c;实际可能有很多级。 tree: [{id: 1,name: 1,children: [{ id: 2, name: 1-1, children: [{id: 7, name: 1-1-1,children: []}]},{ id: 3, name: 1-2 }]},{id: 4,name: 2,children: [{ id: 5, name: 2-1 },{ id: 6, name: 2-2 }]} ]要渲染为下面…

C练习题_14

一、单项选择题&#xff08;本大题共 20小题&#xff0c;每小题 2分&#xff0c;共 40分。在每小题给出的四个备选项中&#xff0c;选出一个正确的答案&#xff0c;并将所选项前的字母填写在答题纸的相应位置上。) 以下叙述不正确的是&#xff08;&#xff09; A.一个C源程序可…
最新文章