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

Expo预构建报错:Metro配置不匹配模板,求解决方向

解决Expo Prebuild中Metro配置不匹配的问题

执行npx expo prebuild时出现Metro skipped: Project metro.config.js does not match prebuild template提示,核心原因是当前配置使用了原生metro-config生成默认配置,而Expo Prebuild要求必须基于@expo/metro-config来构建符合规范的Metro配置。

修复步骤:

  1. 确保项目已安装@expo/metro-config,未安装则执行:

    npm install @expo/metro-config --save-dev
    
  2. 修改metro.config.js,在Expo默认配置基础上保留SVG转换规则,替换后的完整代码如下:

    const { getDefaultConfig } = require('@expo/metro-config');
    
    // 基于当前项目目录生成Expo默认Metro配置
    const config = getDefaultConfig(__dirname);
    
    // 解构原有配置,添加SVG转换规则
    const { transformer, resolver } = config;
    config.transformer = {
      ...transformer,
      babelTransformerPath: require.resolve('react-native-svg-transformer'),
    };
    config.resolver = {
      ...resolver,
      assetExts: resolver.assetExts.filter(ext => ext !== 'svg'),
      sourceExts: [...resolver.sourceExts, 'svg'],
    };
    
    module.exports = config;
    

额外提示:

输出中的android: userInterfaceStyle: Install expo-system-ui in your project to enable this feature提示,若你需要支持系统UI样式切换,可执行npx expo install expo-system-ui安装对应依赖。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 19:45:33