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

React Native ToDo项目使用react-native-calendars遇模块解析错误求助

解决react-native-calendars库"Unable to resolve "./calendar""报错

以下是几个可行的解决步骤:

  • 降级库到稳定版本
    部分新版本的react-native-calendars可能存在文件结构重构导致的路径问题,尝试降级到经过验证的稳定版本:

    npm uninstall react-native-calendars
    npm install react-native-calendars@1.1294.0
    

    或使用yarn:

    yarn remove react-native-calendars
    yarn add react-native-calendars@1.1294.0
    
  • 修正导入路径
    某些版本中Calendar组件的导出方式有变化,尝试直接指定正确的文件路径导入:

    import Calendar from 'react-native-calendars/src/calendar';
    

    之后正常使用<Calendar/>组件即可。

  • 清除Metro缓存
    React Native的Metro缓存可能导致模块解析异常,执行以下命令重置缓存后重启项目:

    npx react-native start --reset-cache
    
  • 彻底重装依赖
    手动删除node_modules文件夹、package-lock.json(或yarn.lock),然后重新安装所有依赖:

    rm -rf node_modules package-lock.json
    npm install
    

    Windows系统执行:

    rmdir /s node_modules
    del package-lock.json
    npm install
    
  • 检查Metro配置
    若项目有自定义metro.config.js,确保配置中没有错误排除react-native-calendars相关模块,默认配置通常无需额外修改,若有自定义规则,需确认包含对该库的正确解析逻辑。

内容的提问来源于stack exchange,提问作者Yaroslav Cubes

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.31 04:36:25