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

Expo 49升级至50后React Native Web构建报错求助

Expo 50 Web构建找不到../../Utilities/Platform的解决方法
  • 清理构建缓存
    执行命令彻底清理Web构建缓存:

    npx expo start --web --clear
    

    也可以手动删除项目根目录下的node_modules/.cache文件夹,再重新启动Web服务。

  • 调整Webpack模块解析配置

    1. 执行npx expo customize:web生成自定义Webpack配置文件
    2. 在生成的webpack.config.js中,为缺失的模块添加别名映射,替换成实际的文件路径:
      const path = require('path');
      
      module.exports = function (config) {
        config.resolve.alias = {
          ...config.resolve.alias,
          '../../Utilities/Platform': path.resolve(__dirname, './path/to/your/Utilities/Platform'),
        };
        return config;
      };
      

    注意替换./path/to/your/Utilities/Platform为文件实际的相对路径。

  • 检查依赖版本匹配
    确认react-native-web等核心Web依赖版本与Expo 50兼容:

    1. 查看当前依赖版本:
      npm ls react-native-web
      
    2. 如果版本不匹配,安装Expo 50指定的兼容版本:
      npm install react-native-web@~0.19.10
      

    (版本号以Expo 50官方文档为准)

  • 明确文件扩展名
    尝试在导入语句中添加文件的实际扩展名,比如将:

    import Platform from '../../Utilities/Platform';
    

    修改为:

    import Platform from '../../Utilities/Platform.js';
    

    (根据文件实际类型调整为.ts或.tsx)

  • 检查Expo Web模块映射规则
    打开app.json或app.config.js,确认expo.web配置中没有错误的模块映射规则,必要时添加正确的映射:

    {
      "expo": {
        "web": {
          "packager": "webpack",
          "moduleAlias": {
            "../../Utilities/Platform": "./src/Utilities/Platform"
          }
        }
      }
    }
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 07:22:19