npm 命令 - 错误:EISDIR:对目录的非法操作,读取 [英] npm command - Error: EISDIR: illegal operation on a directory, read

查看:261
本文介绍了npm 命令 - 错误:EISDIR:对目录的非法操作,读取的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在发出 npm 命令时,我收到一个错误说明,

While issuing the npm command I'm receciving an error stating,

Error: EISDIR: illegal operation on a directory, read
TypeError: Cannot read property 'get' of undefined

我在这方面经历的 SO 帖子(没有解决我的问题):

使用 Node.js 我得到,错误:EISDIR,阅读

Node.JS readFileSync() 函数

我还尝试编辑 .npmrc 文件以删除 ca 条目,即使在此之后问题仍然存在.

I have also tried editing the .npmrc file to remove the ca entry and even after that the issue still persists.

有人可以帮忙吗?

推荐答案

从个人经验来看,根据你的报错信息illegal operation on a directory,我猜测是在执行 npm 时,无法访问目录或文件.

From personal experience, based on your error message illegal operation on a directory, I would guess that while executing npm, it is unable to access a directory or file.

正如其他人所提到的,这通常是与存储 npm 自定义配置的 .npmrc 文件(通常位于用户的主目录 ~/.npmrc 中)相关的错误.需要注意的是,npm 可以有不同级别的配置:

As others have mentioned, this is typically an error related to your .npmrc file (typically located in a user's home directory, ~/.npmrc) which stores custom configurations for npm. It is important to note that npm can have configurations at various levels:

  • 每个项目
  • 每用户
  • 全球
  • 内置

您可以在 npmrc 文档页面.

如果您更喜欢调查问题的根源而不是仅仅删除 .npmrc 文件,您可以通过在文本编辑器(VS Code、记事本等)中打开 .npmrc 或发出以下命令来实现:

If you'd prefer to investigate the source of the issue rather than just removing your .npmrc file you can do so by opening .npmrc in a text editor (VS Code, notepad, etc), or by issuing the command:

npm config edit

在文本编辑器中打开 .npmrc 后,您可以开始查看您拥有的任何配置.如果文件为空或不存在,则您没有任何配置(在该级别),您可以继续调查其他级别的 .npmrc 配置或问题的其他来源.

When .npmrc is opened in your text editor, you can begin reviewing any configurations you have. If the file is empty or doesn't exist then you don't have any configurations (at that level) and you can move on to investigating .npmrc configurations at another level or other sources of the issue.

同样,如果您的 .npmrc 文件只包含以分号 (;) 开头的文本行,那么您没有活动配置,因为分号在 .npmrc 中充当注释(非活动)行.在某些情况下,比如你曾经运行过 npm config list 然后 npm 已经为你创建了一个示例 .npmrc 文件,其中包含要配置的可能设置列表,但所有这些设置都是无效的,因为它们前面有一个分号.下面是运行 npm config list 时由 npm 生成的文件片段:

Similarly if your .npmrc file only contains lines of text that start with a semicolon (;) then you have no active configurations, as a semicolon acts as a commented (inactive) line in the .npmrc. In certain cases, like if you ever ran npm config list then npm has created a sample .npmrc file for you with an list of possible settings to configure, but all these settings are inactive as they are preceded by a semicolon. Below is a snippet of the file generated by npm when npm config list is run:

;;;;
; npm userconfig file
; this is a simple ini-formatted file
; lines that start with semi-colons are comments.
; read `npm help config` for help on the various options

;;;;
; all options with default values
;;;;
; access=null

; allow-same-version=false

一旦您确认您在 .npmrc 中具有活动的自定义配置,则此错误的可能原因可能是您拥有引用计算机上文件位置的任何自定义配置.就我而言,我引用了 .npmrc 中 cacert 属性的 ca 证书的不完整路径:

Once you've verified that you have custom configurations active in .npmrc, then a likely cause of this error might be any custom configurations you have that reference a file location on your machine. In my case I was referencing an incomplete path to my ca certificate for the cacert property in .npmrc:

损坏的配置:

; settings located in ~/.npmrc
cafile=C:/Users/kfrisbie/Documents/certs

注意上面的certs"是对目录的引用,其中 npm 期望对文件的引用,因此当我更新路径以引用我在目录中想要的文件时,npm 再次开始正常运行.

Note that above "certs" was a reference to a directory, where npm was expecting a reference to a file, so when I updated the path to reference the file I intended within the directory, npm began functioning without error again.

固定配置:

; settings located in ~/.npmrc
; note, I was missing the name of the file in the certs directory
cafile=C:/Users/kfrisbie/Documents/certs/trusted_certs.pem

这篇关于npm 命令 - 错误:EISDIR:对目录的非法操作,读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆