因为 npm config set cafile 导致 EISDIR: illegal operation on a directory, read

环境

jenkins

node v16.0.0

npm 7.10

复现操作

执行了

npm config set cafile

后面cafile没有跟内容导致执行任何npm操作都 EISDIR: illegal operation on a directory, read

解决方案

在.npmrc文件中,他会这样体现

cafile=

1.如果知道.npmrc的位置,删除该行即可

如果不知道.npmrc位置

搜索find / -name .npmrc查查,查不到用root查查看

还是查不到的话

2.修改node代码

可以查找该文件 node_modules/npm/lib/utils/config/definitions.js

搜索 cafile 关键词

define('cafile', {
  default: null,
  type: path,
  description: `
    A path to a file containing one or multiple Certificate Authority signing
    certificates. Similar to the \`ca\` setting, but allows for multiple
    CA's, as well as for the CA information to be stored in a file on disk.
  `,
  flatten (key, obj, flatOptions) {
    // always set to null in defaults
    // 这个位置添加一行 return
    if (!obj.cafile)
      return

    const raw = maybeReadFile(obj.cafile)
    if (!raw)
      return

    const delim = '-----END CERTIFICATE-----'
    flatOptions.ca = raw.replace(/\r\n/g, '\n').split(delim)
      .filter(section => section.trim())
      .map(section => section.trimLeft() + delim)
  },
})

在if (!obj.cafile)上一行添加一行return直接退出,否则他会尝试读取目录

保存退出,就可以正常执行了

之后再npm config list 看看配置文件在哪,删掉cafile那一行或者设置为null

npm config set cafile = null

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值