使用 Node.js 我得到,“错误:EISDIR,读取”

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20417118/
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 16:27:36  来源:igfitidea点击:

Using Node.js I get, "Error: EISDIR, read"

node.js

提问by Evan Carroll

When ever I try to open a file I get,

每当我尝试打开文件时,

events.js:72
        throw er; // Unhandled 'error' event
Error: EISDIR, read

回答by Evan Carroll

This error is simple,

这个错误很简单,

cd /tmp
mkdir dir
node -e "var fs = require('fs'); fs.createReadStream( 'dir' );"

EISDIRmeans that the target of the operation is a directory in reality but that the expected filetype of the target is something otherthan a directory.

EISDIR意味着操作的目标是在现实中的目录,但该目标的预期文件类型是什么其他的不是目录。

回答by Mohan Dere

EISDIRerror occurs when you try to open a file, but the path given is a directory.

EISDIR当您尝试打开文件时发生错误,但给定的路径是一个目录。

You can fix this by checking if is it directory-

您可以通过检查它是否是目录来解决此问题-

if (fs.lstatSync(filePath).isDirectory()) {
  return;
}

For more reference see docs here.

有关更多参考,请参阅此处的文档。

回答by Christof

Just came across this error and in my case it was due having used bower linkpreviously to link to local sources which then creates a symlink in the directory. Once I've bower unlinked all the components, it worked again as expected.

刚刚遇到此错误,在我的情况下,这是由于bower link以前用于链接到本地​​源,然后在目录中创建符号链接。一旦我bower unlink编辑了所有组件,它就会再次按预期工作。

Hope this might help someone.

希望这可以帮助某人。