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

升级至React Native 0.73后绝对导入功能失效问题求助

React Native 0.73.0 绝对导入失效修复方案
  • 修改Metro配置文件:在项目根目录的metro.config.js中添加路径别名映射,替换原有配置:

    const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config');
    
    const config = {};
    const defaultConfig = getDefaultConfig(__dirname);
    
    defaultConfig.resolver.alias = {
      ...defaultConfig.resolver.alias,
      'app': './App',
    };
    
    module.exports = mergeConfig(defaultConfig, config);
    
  • 配置代码路径映射:如果项目使用TypeScript或需要IDE代码提示支持,在根目录的tsconfig.json或jsconfig.json中添加以下配置:

    {
      "compilerOptions": {
        "baseUrl": ".",
        "paths": {
          "app/*": ["App/*"]
        }
      }
    }
    
  • 清理缓存并重启服务:执行命令清除Metro缓存,避免缓存残留导致的解析问题:

    npx react-native start --reset-cache
    
  • 移除旧的package.json:删除./App目录下内容为{"name": "app"}的package.json文件,该文件在0.73.0版本中会干扰新的模块解析逻辑。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.04 00:22:28