【问题标题】:Error: EISDIR: illegal operation on a directory, read at Object.readSync错误:EISDIR:对目录的非法操作,在 Object.readSync 处读取
【发布时间】:2021-06-22 16:44:57
【问题描述】:

当我从 android 设备进入我的 react 本机应用程序时,应用程序崩溃并抛出下一个错误:

错误图片:

感谢您的帮助 我尝试删除节点模块并重新安装并删除应用程序并重新构建,但它不起作用

【问题讨论】:

    标签: android react-native gradle build react-native-android


    【解决方案1】:

    这个问题似乎是由于浏览器(我的情况是 Chrome)请求的 Metro bundler 和源地图,我已经列出了解决这个问题的以下步骤。

    注意: 下面提到的补丁脚本只和metro@0.64.0有关。如果您有其他版本,可以尝试修改脚本或在 GitHub 问题中搜索 metro 以查找与您的版本相关的内容。

    1. 通过运行yarn add patch-package 安装patch-package
    2. 接下来,编辑您的package.json 文件并将这一行添加到scripts 中:
    "postinstall": "patch-package"
    
    1. 现在mkdir patches 在您项目的根目录中(如果您还没有的话)。
    2. 将以下脚本添加到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') {
             // We're probably dealing with a virtualised file system where
             // `this.originModulePath` doesn't actually exist on disk.
             // We can't show a code frame, but there's no need to let this I/O
    
    1. 运行yarn postinstall,它应该修补metro@0.64.0

    2. 在 Chrome 开发工具中,取消选中:

      • 启用 JavaScript 源映射
      • 启用 CSS 源映射
    3. 运行react-native start,您应该一切顺利。

    参考:GitHub => react-native-fs => Issue 991

    【讨论】:

      猜你喜欢
      • 2021-07-13
      • 2020-07-25
      • 2021-06-20
      • 1970-01-01
      • 1970-01-01
      • 2022-01-25
      • 2022-01-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多