环境
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