使用npx expo run android生成的调试APK卡在Expo欢迎界面,疑与metro.config有关
问题解决:Expo项目配置nativewind后仅显示默认欢迎页
问题现象
- 执行
npx expo run android构建调试APK后,设备启动应用仅显示默认欢迎界面:Welcome to Expo Start by creating a file in the app directory.,业务代码完全未加载 - 删除
metro.config.js文件并重启Metro服务器后,应用可正常加载业务代码,但nativewind样式功能失效 - 当前使用的Metro配置如下:
const { getDefaultConfig } = require("expo/metro-config"); const { withNativeWind } = require('nativewind/metro'); const config = getDefaultConfig(__dirname) module.exports = withNativeWind(config, { input: './global.css' })

解决方案
以下是针对性的排查和修复步骤:
- 校验global.css路径准确性
确认global.css文件与metro.config.js处于同级目录(项目根目录),若文件在子目录(如src/global.css),需修改配置中的input路径:
module.exports = withNativeWind(config, { input: './src/global.css' })
- 彻底清理缓存与构建产物
缓存冲突是常见诱因,执行以下命令清理后重新构建:
npx expo start --clear rm -rf android/app/build npx expo run android
- 同步依赖版本
版本不兼容可能导致Metro配置异常,更新依赖并修复版本冲突:
npm install nativewind@latest expo@latest npx expo install --fix
- 完善Metro配置写法
确保配置合并逻辑正确,可尝试使用合并配置的方式避免覆盖默认项:
const { getDefaultConfig, mergeConfig } = require('expo/metro-config'); const { withNativeWind } = require('nativewind/metro'); const config = getDefaultConfig(__dirname); module.exports = withNativeWind(mergeConfig(config, { // 可添加其他自定义配置项 }), { input: './global.css' });
- 检查Expo Router目录结构
若使用Expo Router,需确保app目录下存在_layout.jsx/tsx及至少一个页面文件(如index.jsx/tsx),缺失必要路由文件会触发默认欢迎页,而nativewind配置可能放大这一问题。
内容的提问来源于stack exchange,提问作者Eric Uche
相关产品推荐
相关产品推荐

