错误:EISDIR:对目录的非法操作,在 Object.readSync 读取 [英] Error: EISDIR: illegal operation on a directory, read at Object.readSync
问题描述
当我从 Android 设备进入我的 React Native 应用程序时,应用程序崩溃并引发下一个错误:
when i enter to my react native application from android device the app crash and it's throw the next error:
错误图片:
感谢帮助我尝试删除节点模块并重新安装并删除应用程序并再次构建,但它不起作用
thanks for helping I try to delete node modules and reinstall and delete the app and build again and it doesn't work
推荐答案
这个问题似乎是由于浏览器(在我的例子中是 Chrome)请求的 Metro bundler 和源地图,我列出了以下解决这个问题的步骤.
This issue seems to be due to metro bundler and source maps requested by the browser (Chrome in my case), I've listed the steps below in solving this.
注意:下面提到的补丁脚本只与metro@0.64.0
有关.如果您有其他版本,您可以尝试修改脚本或在 GitHub 问题中搜索 metro与您的版本相关的内容.
Note:
The patch script mentioned below is only related to metro@0.64.0
. If you have another version, you can try modifying the script or searching through GitHub issues for metro for something related to your version.
- 通过运行
yarn add patch-package<安装patch-package/code>.
- 接下来,编辑您的
package.json
文件并在scripts
中添加这一行:
- Install patch-package by running
yarn add patch-package
. - Next, edit your
package.json
file and add this line withinscripts
:
"postinstall": "patch-package"
- 现在
mkdir 补丁
位于您项目的根目录中(如果您还没有). - 将下面的脚本添加到
patches/metro+0.64.0.patch
:
- Now
mkdir patches
in your project's root directory (if you don't have one already). - Add the script below into
patches/metro+0.64.0.patch
:
diff --git a/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js b/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js
index 5f32fc5..2b80fda 100644
--- a/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js
+++ b/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js
@@ -346,7 +346,7 @@ class UnableToResolveError extends Error {
try {
file = fs.readFileSync(this.originModulePath, "utf8");
} catch (error) {
- if (error.code === "ENOENT") {
+ if (error.code === "ENOENT" || error.code === 'EISDIR') {
运行
yarn postinstall
,它应该修补metro@0.64.0
.
在 Chrome 开发工具中,取消选中:
In Chrome dev tools, uncheck:
- 启用 JavaScript 源映射
- 启用 CSS 源映射
运行 react-native start
就可以了.
参考:GitHub =>react-native-fs =>问题 991
Reference: GitHub => react-native-fs => Issue 991
这篇关于错误:EISDIR:对目录的非法操作,在 Object.readSync 读取的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!