无论我在什么目录下,无论我在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 npm@2.14.12
3 info using node@v4.2.6
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!


当前回答

所以大多数答案都说它与.npmrc文件有关。

在我的例子中,我正在使用无服务器部署和消息部署无服务器应用程序

EISDIR:在目录上进行非法操作,请断开“/home/malvadao/workspace/project/.build/node_modules”的链接

被扔了出去。

删除.build文件夹对我来说就是这样。它是Typescript编译后生成的文件夹。由于文件夹是在启动无服务器部署命令后重新创建的,因此它足以解决问题并继续流程。

换句话说,手动删除文件夹可能足以让您继续前进,而不需要触摸.npmrc

其他回答

EISDIR代表“错误,是目录”。这意味着NPM试图对一个文件做一些事情,但它是一个目录。在你的例子中,NPM试图“读取”一个目录文件(行:4)。由于操作不能完成,错误被抛出。

这里有三件事要确定。

确保文件存在。如果没有,则需要创建它。(如果NPM依赖于文件中的任何特定信息,你将需要在那里有这些信息)。 确保它实际上是一个文件,而不是一个目录。 它具有正确的权限。可以使用“sudo chmod 777 FILE_NAME”将文件修改为拥有所有权限。(注意:你给了读,写和执行权限的文件上的每个人)

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

在我的情况下,我在MAC (Mojave OS)中使用以下命令安装create-react-app时遇到了这个问题:

sudo npm install create-react-app -g

得到了这样的错误:

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'

我读过npm.community尝试安装没有sudo:

npm install create-react-app -g

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

在我的例子中,问题是空格字符在源文件夹的名称中(Windows 10)。

在我的情况下,我正在angularv10与材料工作。我改变了一些脚本文件,忘记在脚本数组中删除这些空的“”

scripts: [.....等等,等等,""

删除这些空的""

NPM clear-cache——force

关闭并打开vscode

它工作。