使用标准react-native init MyApp
创建新的react native项目并首次运行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)
我尝试运行建议的程序,但仍然看到相同的问题。我看过几篇有关类似问题的文章,但似乎没有什么特别的话说如何用react-native解决问题。
macOS: 10.13.6
node: 8.11.3
react-native-cli: 2.0.1
react-native: 0.57.1
答案 0 :(得分:111)
可以尝试:
npm add @babel/runtime
或升级babel运行时:
"@babel/runtime": "7.0.0-beta.55"
答案 1 :(得分:1)
在执行之前,您应该先退出地铁终点站
forEach
答案 2 :(得分:0)
尝试首先更新您的npm版本
npm update -g npm@version
或sudo npm -gf update npm@version
,然后只需在您的react native项目中添加babel运行时
npm add @babel/runtime
答案 3 :(得分:0)
尝试升级您的软件包。您可能有一个导致问题的旧软件包:
yarn upgrade-interactive --latest
答案 4 :(得分:0)
由于反应本机路径中createStackNavigator
,createAppContainer
,createSwitchNavigator
的错误排列,我遇到了同样的问题
答案 5 :(得分:0)
您应该为您的项目添加并安装babel
npm add @babel/runtime
npm install
如果错误未解决,请尝试:
npm start --reset-cache
答案 6 :(得分:0)
当前错误消息建议采取以下步骤解决此问题:
最后一个为我解决了。
答案 7 :(得分:0)
我今天(2021 年 4 月)遇到了这个问题,我只能通过从我的 webpack 配置中删除 webpack-node-externals
包来解决它。
答案 8 :(得分:0)
如果上面列出的解决方案都不适用于我,我不得不去node_modules/jest-haste-map/build/index.js
改变了const crawl = canUseWatchman && this._options.useWatchman ? _watchman.default : _node.default;
到const crawl = canUseWatchman && this._options.useWatchman ? _node.default : _node.default;
答案 9 :(得分:0)
对我来说,解决方案是 (Mac):
npx browserslist@latest --update-db -g
npm cache verify
如果还是不行:
npm cache verify
npx browserslist@latest --update-db -g
答案 10 :(得分:0)
对我来说问题是@babel/runtime 被安装为一个开发依赖,而不是一个普通的(非开发)依赖