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


当前回答

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

改变:

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

到这个:

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

其他回答

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

在设置样板代码时,我也遇到了类似的问题。它将我的bundle.js文件作为目录读取。正如这里所述。EISDIR意味着它是一个目录而不是一个文件。为了解决这个问题,我删除了该文件,然后重新创建(它最初是自动创建的)。 如果你找不到文件(因为它是隐藏的),只需使用终端找到并删除它。

我也遇到过类似的问题。我使用命令设置cafile:

npm config set cafile PATH_TO_CERTIFICATE

我可以通过删除证书文件设置并设置strict-ssl = false来解决这个问题。

就我而言,以下步骤解决了我的问题:

终止npm进程(CTRL + C) 删除整个文件夹 创建一个新的 再次运行NPM

我也有同样的问题。

最近刚刚删除了用户目录中的.npmrc文件,之后,我运行了npm init -y

作品!