React Native - 无法从“index.js"解析模块“@babel/runtime/helpers/interopRequireDefault" [英] React Native - Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from 'index.js'

查看:473
本文介绍了React Native - 无法从“index.js"解析模块“@babel/runtime/helpers/interopRequireDefault"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

中所述,无法解析模块`@babel/runtime/helpers/interopRequireDefault`,我遇到了同样的错误,该问题的解决方案并不能解决我的问题.

As mentioned in Unable to resolve module `@babel/runtime/helpers/interopRequireDefault`, I am experiencing the same error and the solution for that question doesn't solve the problem in my case.

React Native - 无法解析模块 `@babel/runtime/helpers/interopRequireDefault` 解决了我的问题.

我正在使用

 OS: Windows 10 10.0.18362
    CPU: (8) x64 Intel(R) Core(TM) i5-8250U CPU @ 1.60GHz
    Memory: 2.03 GB / 7.92 GB
  Binaries:
    Node: 12.13.1 - C:\Program Files\nodejs\node.EXE
    Yarn: 1.19.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.12.1 - C:\Program Files\nodejs\npm.CMD
  IDEs:
    Android Studio: Version  3.5.0.0 AI-191.8026.42.35.5977832
  npmPackages:
    react: 16.9.0 => 16.9.0
    react-native: 0.61.4 => 0.61.4

错误说:

error: bundling failed: Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `index.js`: @babel/runtime/helpers/interopRequireDefault could not be found within the project.

If you are sure the module exists, try these steps:
 1. Clear watchman watches: watchman watch-del-all
 2. Delete node_modules: rm -rf node_modules and run yarn install
 3. Reset Metro's cache: yarn start --reset-cache
 4. Remove the cache: rm -rf /tmp/metro-*
    at ModuleResolver.resolveDependency (C:\ReactProjects\testy\node_modules\metro\src\node-haste\DependencyGraph\ModuleResolution.js:186:15)
    at ResolutionRequest.resolveDependency (C:\ReactProjects\testy\node_modules\metro\src\node-haste\DependencyGraph\ResolutionRequest.js:52:18)
    at DependencyGraph.resolveDependency (C:\ReactProjects\testy\node_modules\metro\src\node-haste\DependencyGraph.js:282:16)
    at Object.resolve (C:\ReactProjects\testy\node_modules\metro\src\lib\transformHelpers.js:267:42)
    at C:\ReactProjects\testy\node_modules\metro\src\DeltaBundler\traverseDependencies.js:426:31
    at Array.map (<anonymous>)
    at resolveDependencies (C:\ReactProjects\testy\node_modules\metro\src\DeltaBundler\traverseDependencies.js:423:18)
    at C:\ReactProjects\testy\node_modules\metro\src\DeltaBundler\traverseDependencies.js:275:33
    at Generator.next (<anonymous>)
    at asyncGeneratorStep (C:\ReactProjects\testy\node_modules\metro\src\DeltaBundler\traverseDependencies.js:87:24)
 BUNDLE  [android, dev] ./index.js ░░░░░░░░░░░░░░░░ 0.0% (0/1), failed.

该模块存在,我已经尝试了上述步骤,但仍然无法正常工作.该应用程序实际构建成功,并显示消息 Deprecated Gradle features were used in this build,使其与 Gradle 6.0 不兼容.当应用程序运行时,会出现与上述相同的错误.任何帮助表示赞赏.

The module exists and I have tried the mentioned steps but still it doesnt work. The app actually builds successfully with message Deprecated Gradle features were used in this build, making it incompatible with Gradle 6.0. When the app runs the same error as above shows up. Any help is appreciated.

推荐答案

我的案例中,问题不是RN造成的,而是watchman造成的.

In my case, the problem was not caused by RN, but by watchman.

在修复潜在错误之前,有两种方法可以解决此问题:

There are two ways to solve this until a potential bug is fixed:

首先是卸载watchman.

或者手动编辑文件node_modules/jest-haste-map/build/index.js来改变:

Or manually edit the file node_modules/jest-haste-map/build/index.js to change:

    const crawl =
      canUseWatchman && this._options.useWatchman
        ? _watchman.default
        : _node.default;

致:

    const crawl =
      canUseWatchman && this._options.useWatchman
        ? _node.default
        : _node.default;

后者当然不会因软件包升级而持续存在.

The latter will of course not persist over package upgrades.

这篇关于React Native - 无法从“index.js"解析模块“@babel/runtime/helpers/interopRequireDefault"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆