React Native Metro 无法解析模块

问题描述 投票:0回答:0

在React Native从

0.69.10
更新到
0.70.9
的过程中,我把Metro更新到
v0.72.3

运行应用程序时,出现错误

error: Error: Unable to resolve module react-native-gesture-handler from /path-to-project/index.js: react-native-gesture-handler could not be found within the project or in these directories:
  node_modules
  ../node_modules
  ../../../../node_modules

但是,我检查了

node_modules
,发现
node_modules/react-native-gesture-handler
存在

这个问题不仅仅发生在

react-native-gesture-handler
身上。
react-native-screens
redux-form
等也会发生这种情况,这让我认为这是 Metro 分辨率问题。

然而,Metro 提到它试图查看的路径似乎是正确的,所以我不确定这里会发生什么情况

升级前一切正常

我试过的

我试过在运行启动脚本时重置缓存

react-native start --reset-cache
但是它不起作用

我也试过禁用Hermes。好像也不是这样

我还清除了iOS和Android缓存,清除了

node_modules
并重新安装了所有内容,但无济于事

我还确保所有地铁包的版本都是正确的

v0.72.3

我试过

rm -rf ${TMPDIR:-/tmp}/metro-*
清除缓存,也没用

我也尝试通过添加

将地铁更新到
v0.76.4

的最新版本
  "resolutions": {
    "metro": "^0.76.4"
  },

但是出现同样的错误

javascript react-native import node-modules metro-bundler
© www.soinside.com 2019 - 2024. All rights reserved.