无论我在什么目录下,无论我在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!


当前回答

在我的情况下,我在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

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

其他回答

这发生在我使用npm publish -access public命令时。项目包含名为package.json的目录。这个错误是可悲的-因为项目必须有这个目录和命名确切的包。Json(它是测试用例fixture的一部分,用于断言这个库的正确行为)。

对我来说,这是因为我走错了路;它应该是一个文件的路径,但我错误地使用了一个目录的路径:

改变:

path.resolve(__dirname, '../');

到这个:

path.resolve(__dirname, '../.env')

我使用的是Laravel v8.56.0的Mix v6.0.29

在webpack.mix.js中,当复制目录时使用

mix.copyDirectory(“resources/js”, “public/js”);

检查内部文件夹,它不应该包含点/s(.),否则,这个错误将弹出。

我认为对于这个特定的版本,路径(或文件夹)与点/s后面跟着一些字符,将类似于文件扩展名,然后将被视为“文件”,不管它是否是“文件夹”。

做一个完整的卸载,包括删除路径等,重新安装已经解决了这个问题,虽然非常奇怪的问题。

如何从Windows中完全删除node.js

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