解决run `npm audit fix` to fix them

今天给站点添加看板娘的时候,npm安装插件出现了“run npm audit fix to fix them”的报错,一般情况下根据提示运行 npm audit fix 就能解决这个问题了,但是众所周知,一下子就能解决的问题就不叫问题了。这里放出两个解决方案,第一种不行就用第二种。

出现原因

这个问题是因为npm安装插件时依赖版本不匹配所造成的,可能是所用的依赖太老,所以npm的自动检查发现了高危漏洞 high vulnerabilities

added 253 packages from 162 contributors and audited 1117 packages in 42.157s
found 5 vulnerabilities (1 low, 4 high)
run `npm audit fix` to fix them, or `npm audit` for details html

解决方案

方案一: 

这是最简单的,但是成功的概率小,因为有些依赖不能被自动修复。

运行所提示的修复命令:

npm audit fix

如果返回0 vulnerabilities就修复成功,否则继续:

npm audit fix --force
npm audit

如果不行的话就得采用第二种方案

方案二:

既然现有的npm镜像不能自动修复依赖,那我们就换一个镜像源:

npm install -g nrm

如果这一步无法安装,提示 permission denied 那就是权限不够,使用sudo加权安装:

sudo npm install -g nrm

安装完成之后可以使用下面的命令查看各个仓库的地址:

nrm ls

可以看到以下内容:

wei@MacBook-Pro Hexo % nrm ls

npm ---------- https://registry.npmjs.org/
yarn --------- https://registry.yarnpkg.com/
tencent ------ https://mirrors.cloud.tencent.com/npm/
cnpm --------- https://r.cnpmjs.org/
taobao ------- https://registry.npmmirror.com/
npmMirror ---- https://skimdb.npmjs.com/registry/

​第一个npm是npm官方的仓库,既然它更新不了,我们就换一个仓库,这里我选择的是taobao:

wei@MacBook-Pro Hexo % nrm use taobao


Registry has been set to: https://registry.npmmirror.com/

可以看到,仓库已被设定为 https://registry.npmmirror.com/ ,接下来就可以再次尝试安装插件了,这次应该不会报错,且插件正常安装使用~

版权声明:
作者:小鱼
链接:https://afish.org/index.php/2022/09/26/%e8%a7%a3%e5%86%b3run-npm-audit-fix-to-fix-them/
来源:小鱼的blog
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
< <上一篇
下一篇>>