node.js NPM 卡住给出相同的错误 EISDIR: Illegal operation on a directory, read at error (native)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/34959038/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 19:47:59  来源:igfitidea点击:

NPM stuck giving the same error EISDIR: Illegal operation on a directory, read at error (native)

node.jswindowscmdnpmfile-permissions

提问by AnotherMike

I am stuck with this error no matter what directory I am in, and what I type after "npm" in cmd.exe. Here is the npm-debug.log:

无论我在哪个目录中,无论我在 cmd.exe 中的“npm”之后输入什么,我都会遇到这个错误。这是 npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ 'C:\Program Files\nodejs\node.exe',
1 verbose cli   'C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js' ]
2 info using [email protected]
3 info using [email protected]
4 verbose stack Error: EISDIR: illegal operation on a directory, read
4 verbose stack     at Error (native)
5 verbose cwd C:\Users\me
6 error Windows_NT 6.1.7601
7 error argv "C:\Program Files\nodejs\node.exe" "C:\Program Files\nodejs\node_modules\npm\bin\npm-cli.js"
8 error node v4.2.6
9 error npm  v2.14.12
10 error code EISDIR
11 error errno -4068
12 error syscall read
13 error eisdir EISDIR: illegal operation on a directory, read
13 error eisdir This is most likely not a problem with npm itself
13 error eisdir and is related to npm not being able to find a package.json in
13 error eisdir a package you are trying to install.
14 verbose exit [ -4068, true ]

I have tried and uninstalling/reinstalling nodejs multiple times, I even deleted npm and npm-cache folders in C:\Users\me\AppData\Roaming. I'm not sure what went wrong to cause this. One second it was working fine, and now I can't get rid of this error. The explanation in the log does not make sense, as it gives this error in any directory. I should note that running a command prompt as administrator does not give this error. I'm pulling my hair out this Friday evening trying to get this fixed, any help would be greatly appreciated!

我已经多次尝试卸载/重新安装 nodejs,我什至删除了 C:\Users\me\AppData\Roaming 中的 npm 和 npm-cache 文件夹。我不确定是什么问题导致了这个。一秒钟它工作正常,现在我无法摆脱这个错误。日志中的解释没有意义,因为它在任何目录中都会出现此错误。我应该注意,以管理员身份运行命令提示符不会出现此错误。这个星期五晚上我正在拔头发试图解决这个问题,任何帮助将不胜感激!

采纳答案by user1460043

I ran into the same problem while I was changing some npm settings. I did a mistake with one npm config setcommand and this added a line referring to a non-existing directory to C:\Users\{User}\.npmrc. After I deleted that line manually from .npmrc, the problem was gone.

我在更改一些 npm 设置时遇到了同样的问题。我在一个npm config set命令上犯了一个错误,这添加了一行引用不存在的目录到C:\Users\{User}\.npmrc. 从 手动删除该行后.npmrc,问题就消失了。

回答by MauricioLeal

EISDIRstands for "Error, Is Directory". This means that NPM is trying to do something to a file but it is a directory. In your case, NPM is trying to "read" a file which is a directory (Line: 4). Since the operation cannot be done the error is thrown.

EISDIR代表“错误,是目录”。这意味着 NPM 试图对一个文件做一些事情,但它是一个目录。在您的情况下,NPM 试图“读取”一个目录文件(第 4 行)。由于操作无法完成,因此抛出错误。

Three things to make sure here.

这里要确保三件事。

  1. Make sure the file exists. If it does not, you need to create it. (If NPM depends on any specific information in the file, you will need to have that information there).
  2. Make sure it is in fact a file and not a directory.
  3. It has the right permissions. You can change the file to have all permissions with "sudo chmod 777 FILE_NAME". (Careful: You are giving Read, Write and Execute permissions to every one on that file)
  1. 确保文件存在。如果没有,您需要创建它。(如果 NPM 依赖于文件中的任何特定信息,您将需要在那里拥有该信息)。
  2. 确保它实际上是一个文件而不是目录。
  3. 它具有正确的权限。您可以使用“sudo chmod 777 FILE_NAME”将文件更改为具有所有权限。(小心:您正在为该文件的每个人授予读取、写入和执行权限)

回答by PeeJee

Had the same problem today after i've upgraded my npm from version 6.4.1 to version 6.5.0. I fixed this by downloading the .pkg installer (recommended for most users) from node.jsand runned it afterwards.

在我将 npm 从 6.4.1 版升级到 6.5.0 版后,今天遇到了同样的问题。我通过从node.js下载 .pkg 安装程序(推荐给大多数用户)来解决这个问题,然后运行它。

回答by Rob

In my case I was getting the "EISDIR: illegal operation on a directory, read" because in my .angular-cli.json file I wasn't providing a full path in "scripts:"

在我的情况下,我得到了“EISDIR:对目录的非法操作,读取”,因为在我的 .angular-cli.json 文件中,我没有在“脚本:”中提供完整路径

For example I had

例如我有

"scripts": [
        "../node_modules/hammerjs",
        "../node_modules/moment"
      ],

In fact it should have been

其实应该是

"scripts": [
        "../node_modules/hammerjs/hammer.min.js",
        "../node_modules/moment/min/moment.min.js"
      ],

回答by rncrtr

I had the same issue on Mac OS X (installed with homebrew), and the .npmrc is not the only place node stored config variables. There is a glocal npmrc config file in /usr/local/etc that you have to edit using this command:

我在 Mac OS X(安装了自制软件)上遇到了同样的问题,并且 .npmrc 不是唯一的地方节点存储配置变量。/usr/local/etc 中有一个 glocal npmrc 配置文件,您必须使用以下命令对其进行编辑:

sudo nano npmrc

Remove the ca=line, or whatever the config setting was that broke your install, save that file, and try npm again, and you should see it working.

删除该ca=行,或者任何破坏安装的配置设置,保存该文件,然后再次尝试 npm,您应该会看到它正常工作。

回答by datayeah

These strange errors occured recently on my OSX machine.

这些奇怪的错误最近发生在我的 OSX 机器上。

I could help myself the quick & dirty way by running:

我可以通过运行来帮助自己快速而肮脏的方式:

sudo chmod -R 777 /usr/local/lib/node_modules/

sudo chmod -R 777 /usr/local/lib/node_modules/

Something seemed to have messed up the access rights of all global node modules.

似乎有些东西弄乱了所有全局节点模块的访问权限。

回答by Miniwe

For me fixing was add slash after directory name

对我来说修复是在目录名称后添加斜杠

回答by Rafael Paz

In my case I forgot to pass the fullpath of one of the file it was asking. After passing full path of the file worked :)

在我的情况下,我忘记传递它正在询问的文件之一的完整路径。传递文件的完整路径后:)

回答by Ritesh

In my case, i was facing this issue while installing create-react-appin MAC (Mojave OS)with following command :

就我而言,我create-react-appMAC (Mojave OS)使用以下命令安装时遇到了这个问题:

sudo npm install create-react-app -g

and got errors like this :

并得到这样的错误:

npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/scheduler'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/symbol'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/testing'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/util'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/src/webSocket'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/symbol'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/testing'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/util'
npm WARN tar EISDIR: illegal operation on a directory, open '/usr/local/lib/node_modules/.staging/rxjs-a84420a7/webSocket'

I have read npm.communitythat try to install without sudo:

我已阅读npm.community尝试在没有安装的情况下进行安装sudo

npm install create-react-app -g

and it actually solved my issue ..!!

它实际上解决了我的问题..!!

回答by Friendly-Robot

If your problem is associated with the React Native packager. Try resetting the cache with react-native start --reset-cache.

如果您的问题与 React Native 打包器有关。尝试使用 重置缓存react-native start --reset-cache