【npm】拉取项目后,安装依赖报错怎么办?npm ERR! notarget No matching version found for...

前提:npm i 之后,安装依赖失败

【报错示例】

npm ERR! code ETARGET
npm ERR! notarget No matching version found for raphael@2.2.0-c.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

npm ERR! A complete log of this run can be found in:

报错提示无法匹配依赖对应的版本号,导致下载失败。

【解决方案】

在了解 npm 语义版本控制及语义化版本号的表示后,得出解决方案。package-lock.json 文件中,找出安装失败的依赖所有版本号,在前面加 ^~ 符号或者删除版本号。

依赖版本号表示:x.y.z
x表示主版本,y表示次版本,z表示补丁版本

^符号表示版本不升级,次版本、补丁版本升级到最新。^2.2.0 等价于 2.2.0 >= ^2.2.0 < 3.0.0。
~符号只会升级补丁版本。例如:~2.2.0 等价于 2.2.0 >= ~2.2.0 <2.3.0。
删除版本号等于""空符号表示更新到最新版本。

【解决示例】

1、加 ^ 符号

// 版本号前面加 ^ 符号
"node_modules/raphael": {
      "version": "^2.2.0-c",
      "license": "MIT",
      "dependencies": {
        "eve": "git://github.com/adobe-webplatform/eve.git#eef80ed"
      }
},
...
"raphael": {
      "version": "^2.2.0-c",
      "requires": {
        "eve": "git://github.com/adobe-webplatform/eve.git#eef80ed"
      }
},
...
"tui-chart": {
      "version": "3.11.3",
      "requires": {
        "core-js": "^3.6.4",
        "raphael": "https://github.com/nhn/raphael.git#^2.2.0-c", //设置空版本号时记得把 # 也去掉
        "tui-code-snippet": "^2.3.1"
      },
      "dependencies": {
        "tui-code-snippet": {
          "version": "2.3.3"
        }
      }
},

同理可得加~符号…。

2、删除版本号

// 删除版本号
"node_modules/raphael": {
      "version": "",
      "license": "MIT",
      "dependencies": {
        "eve": "git://github.com/adobe-webplatform/eve.git#eef80ed"
      }
},
...
"raphael": {
      "version": "",
      "requires": {
        "eve": "git://github.com/adobe-webplatform/eve.git#eef80ed"
      }
},
...
"tui-chart": {
      "version": "3.11.3",
      "requires": {
        "core-js": "^3.6.4",
        "raphael": "https://github.com/nhn/raphael.git", //设置空版本号时记得把 # 也去掉
        "tui-code-snippet": "^2.3.1"
      },
      "dependencies": {
        "tui-code-snippet": {
          "version": "2.3.3"
        }
      }
},
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值