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

升级至Expo 46后应用启动失败,报TypeError等错误求助

解决Expo 46升级后的启动错误

1. 修复_reactNative.Image.propTypes.source未定义错误

React Native 0.68+(Expo 46对应RN 0.69版本)已移除核心组件的PropTypes默认导出,部分旧依赖库仍在使用Image.propTypes会触发此错误。解决步骤:

  • 安装兼容的PropTypes包:
    npm install deprecated-react-native-prop-types --save
    
  • 修改babel.config.js,添加插件自动替换旧PropTypes引用:
    module.exports = function(api) {
      api.cache(true);
      return {
        presets: ['babel-preset-expo'],
        plugins: [
          [
            'module-resolver',
            {
              alias: {
                'react-native/Libraries/Image/ImagePropTypes': 'deprecated-react-native-prop-types',
                'react-native/Libraries/Image/Image': 'deprecated-react-native-prop-types',
              },
            },
          ],
        ],
      };
    };
    
  • 若上述方法无效,检查项目自定义代码是否直接使用Image.propTypes,替换为import PropTypes from 'prop-types'并手动定义PropTypes规则。

2. 修复模块解析错误(找不到http://192.168.xx.xx:19000/index.ts)

该错误是Metro误将URL当作本地模块解析导致的,可按以下方式排查:

  • 清除Metro缓存:
    npx expo start --clear
    
  • 全局搜索项目代码,检查是否存在错误的模块导入语句(误将http://192.168.xx.xx:19000写入import路径),找到后修正。
  • 检查metro.config.js配置,若有自定义路径映射或asset规则,暂时注释后测试,建议使用Expo默认配置:
    const { getDefaultConfig } = require('expo/metro-config');
    const config = getDefaultConfig(__dirname);
    module.exports = config;
    

3. 修复"main"未注册错误

此错误是前序模块加载失败导致AppRegistry.registerComponent未执行,解决前两个错误后重启Metro即可自动修复。若仍出现:

  • 确认项目入口文件(通常为App.tsx或index.ts)中存在正确的注册代码,Expo项目一般由expo/AppEntry自动处理,自定义入口需确保:
    import { AppRegistry } from 'react-native';
    import App from './App';
    import { name as appName } from './app.json';
    
    AppRegistry.registerComponent(appName, () => App);
    

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.13 23:20:36