首页 > 解决方案 > 错误:捆绑失败:错误:无法解析模块`react-native

问题描述

我更新了所有依赖项以在 React Native 中使用钩子。他们是:

"axios": "^0.18.0",
"expo": "^32.0.0",
"react": "^16.8.6",
"react-native": "^0.59.5",
"react-navigation": "^3.9.0"

在更新依赖项之前,开发服务器运行良好,但更新到最新版本后,它显示错误:

error: bundling failed: Error: Unable to resolve module `react-native/Libraries/Components/View/ViewStylePropTypes` from `C:\Koolpeace\apps\node_modules\react-native-reanimated\src\createAnimatedComponent.js`: Module `react-native/Libraries/Components/View/ViewStylePropTypes` does not exist in the Haste module map
INFO
21:13
This might be related to https://github.com/facebook/react-native/issues/4968
INFO
21:13
To resolve try the following:
INFO
21:13
  1. Clear watchman watches: `watchman watch-del-all`.
INFO
21:13
  2. Delete the `node_modules` folder: `rm -rf node_modules && npm install`.
INFO
21:13
  3. Reset Metro Bundler cache: `rm -rf /tmp/metro-bundler-cache-*` or `npm start -- --reset-cache`.
INFO
21:13
  4. Remove haste cache: `rm -rf /tmp/haste-map-react-native-packager-*`.

我尝试了互联网上的所有内容。我清空了缓存。我清空了各种缓存,包括

react-native start --reset-cache

他们都没有为我工作。我删除了 node_modules 并重新安装了几次。是一样的。我只写了简单的东西,问题一定是依赖关系中的崩溃。但我不知道哪里出错了。我也试过降级。直到

"react": "^16.8",
"react-native": "^0.59"

支持挂钩的最低版本。它也没有工作。

我尝试在 Expo Snack 上编写代码。零食引发类型错误:未定义不是函数。附近)使用效果...

我猜博览会小吃平台使用过时的 React 和 React Native。

现在,我能做什么?如何运行开发服务器并继续使用二维码和我的手机调试?

标签: react-nativeexpo

解决方案


Expo 中仍然不支持 Hooks。有一个关于此的功能请求,但仍在进行中:https ://expo.canny.io/feature-requests/p/support-react-1680-aka-hooks


推荐阅读