无法解析模块`@babel/runtime/helpers/interopRequireDefault`

Chr*_*ton 56 react-native

当使用标准创建一个新的反应本机项目react-native init MyApp并且react-native run-ios第一次运行时,我看到以下错误

error: bundling failed: Error: Unable to resolve module `@babel/runtime/helpers/interopRequireDefault` from `/Users/chrisedgington/Development/ReactNative/SixNationsPredictor/index.js`: Module `@babel/runtime/helpers/interopRequireDefault` does not exist in the Haste module map

This might be related to https://github.com/facebook/react-native/issues/4968
To resolve try the following:
  1. Clear watchman watches: `watchman watch-del-all`.
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.
    at ModuleResolver.resolveDependency (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/node-haste/DependencyGraph/ModuleResolution.js:209:1301)
    at ResolutionRequest.resolveDependency (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/node-haste/DependencyGraph/ResolutionRequest.js:83:16)
    at DependencyGraph.resolveDependency (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/node-haste/DependencyGraph.js:238:485)
    at Object.resolve (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/lib/transformHelpers.js:180:25)
    at dependencies.map.result (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:311:29)
    at Array.map (<anonymous>)
    at resolveDependencies (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:307:16)
    at /Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:164:33
    at Generator.next (<anonymous>)
    at step (/Users/chrisedgington/Development/ReactNative/MyApp/node_modules/metro/src/DeltaBundler/traverseDependencies.js:266:307)
Run Code Online (Sandbox Code Playgroud)

我试过运行建议,但仍然看到相同的问题.我已经看过一些关于类似问题的帖子,但没有具体说明如何在react-native中解决问题.

macOS: 10.13.6 
node: 8.11.3
react-native-cli: 2.0.1
react-native: 0.57.1
Run Code Online (Sandbox Code Playgroud)

JRK*_*JRK 127

快去尝试一下:

npm add @babel/runtime

或者升级babel运行时:

"@babel/runtime": "7.0.0-beta.55"

  • 我可以知道这个错误表明什么以及这个解决方案如何解决这个问题吗? (4认同)
  • 看起来问题已被记录https://github.com/facebook/react-native/issues/21310 (3认同)
  • @ th3g3ntl3m3n确保在安装软件包后重新启动metro构建器. (3认同)
  • 在安装`@babel/runtime`之后,它对我有了'npm start - --reset-cache`. (3认同)

小智 17

我尝试了上面提到的所有事情,今晚我发现自己又在这里了。

从 nrwl mono 存储库运行,我必须进入有问题的应用程序并运行。

jest --clearCache


Ami*_*ati 9

你应该为你的项目添加并安装 babel

npm add @babel/runtime
npm install
Run Code Online (Sandbox Code Playgroud)

如果错误未修复,请尝试:

npm start --reset-cache
Run Code Online (Sandbox Code Playgroud)


Raj*_*dka 6

在执行之前你应该先退出地铁站

npm add @babel/runtime
npm install
Run Code Online (Sandbox Code Playgroud)


mys*_*obo 6

对我来说,问题是 @babel/runtime 是作为开发依赖项安装的,而不仅仅是普通(非开发)依赖项


Gen*_*Jam 5

当前错误消息建议采取以下步骤来解决此问题:

  1. 清晰的守望者手表:守望者 watch-del-all
  2. 删除node_modules: rm -rf node_modules 并运行yarn install
  3. 重置 Metro 的缓存:yarn start --reset-cache
  4. 删除缓存: rm -rf /tmp/metro-*

最后一位为我解决了这个问题。