You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Redux构建Uber克隆项目时遇模块解析语法错误求助

问题描述

在使用Redux构建Uber克隆项目时,出现模块解析错误,具体报错如下:

无法从D:\uber-clone\node_modules\react-redux\lib\index.js解析模块../utils/reactBatchedUpdates:
以下文件均不存在:

  • node_modules\react-redux\utils\reactBatchedUpdates(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)
  • node_modules\react-redux\utils\reactBatchedUpdates\index(.native|.ios.ts|.native.ts|.ts|.ios.tsx|.native.tsx|.tsx|.ios.js|.native.js|.js|.ios.jsx|.native.jsx|.jsx|.ios.json|.native.json|.json)

报错代码位置:

16 | var _withSelector = require("use-sync-external-store/shim/with-selector");
17 |
18 | var _reactBatchedUpdates = require("../utils/reactBatchedUpdates");
|                                     ^
19 |
20 | var _batch = require("../utils/batch");
21 |

附带原生错误栈(核心问题为模块缺失,此部分可忽略):
ABI46_0_0facebook::ABI46_0_0React::JSIExecutor::defaultTimeoutInvoker(std::__1::function<void ()> const&, std::__1::function<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> ()>)
ABI46_0_0facebook::ABI46_0_0React::JSIExecutor::defaultTimeoutInvoker(std::__1::function<void ()> const&, std::__1::function<std::__1::basic_string<char, std::__1::char_traits, std::__1::allocator> ()>)
FF408738-D75B-3061-AD99-4A929C0162D2
FF408738-D75B-3061-AD99-4A929C0162D2
_dispatch_main_queue_callback_4CF
A408A063-A023-3AAA-A674-0FF01607F818
A408A063-A023-3AAA-A674-0FF01607F818
CFRunLoopRunSpecific
GSEventRunModal
F9E6CF6F-3B15-3C66-8C35-951AFD4D0CC4
UIApplicationMain
Expo Go
1A4BE407-C230-309B-AEAB-8E9C62BD377A

解决方案

该问题由react-redux依赖安装不完整或版本不兼容导致,按以下步骤解决:

  • 删除旧依赖文件与锁文件
    执行命令清理:

    # Mac/Linux
    rm -rf node_modules package-lock.json yarn.lock
    # Windows
    rmdir /s node_modules && del package-lock.json yarn.lock
    
  • 重新安装依赖
    重新拉取完整依赖:

    npm install
    # 或使用yarn
    yarn install
    
  • 检查并修复版本兼容性
    确保react-redux版本与React、Redux版本匹配:

    • React 18+适配react-redux v8.x
    • React 17及以下适配react-redux v7.x
      版本不兼容时,手动指定版本安装:
    # 安装最新v8.x版本
    npm install react-redux@latest
    # 或安装稳定v7.x版本
    npm install react-redux@7.2.9
    
  • 清理Metro缓存(Expo/React Native项目)
    因使用Expo Go,需清除Metro缓存:

    npx expo start --clear
    
  • 清理全局缓存(若上述步骤无效)
    若仍存在文件缺失问题,清理npm/yarn全局缓存后重新安装:

    # npm
    npm cache clean --force
    # yarn
    yarn cache clean
    

内容的提问来源于stack exchange,提问作者wl qk

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.17 02:10:54