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

Expo 48升级至52后已安装expo-modules-core仍遇解析错误求助

Expo 48升级至52后无法解析expo-modules-core的问题

将Expo从48版本升级到52后,已按建议安装expo-modules-core,但仍收到以下错误:

Android Bundling failed 66ms index.js (1 module)
Unable to resolve "expo-modules-core" from "node_modules/expo/src/Expo.ts"

这是一个Expo裸React Native应用,package.json内容如下:

{
  "name": "bApp",
  "version": "1.1.4",
  "scripts": {
    ...
  },
  "dependencies": {
    "@babel/runtime": "^7.26.0",
    "@config-plugins/react-native-ble-plx": "^7.0.0",
    "@ethersproject/address": "^5.7.0",
    "@expo/config-plugins": "~9.0.12",
    "@invertase/react-native-apple-authentication": "^2.4.0",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-native-firebase/app": "^21.6.2",
    "@react-native-firebase/auth": "^21.6.2",
    "@react-native-firebase/crashlytics": "^21.6.2",
    "@react-native-firebase/firestore": "^21.6.2",
    "@react-native-firebase/functions": "^21.6.2",
    "@react-native-firebase/messaging": "^21.6.2",
    "@react-native-firebase/perf": "^21.6.2",
    "@react-native-google-signin/google-signin": "^10.1.2",
    "@react-native-masked-view/masked-view": "0.3.2",
    "@react-native/assets-registry": "^0.74.88",
    "@react-navigation/bottom-tabs": "^6.6.1",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "@react-navigation/stack": "^6.4.1",
    "@reduxjs/toolkit": "^1.9.7",
    "@shopify/flash-list": "1.7.1",
    "@walletconnect/modal-react-native": "^1.1.0",
    "expo": "^52.0.23",
    "expo-apple-authentication": "^7.1.2",
    "expo-asset": "~11.0.1",
    "expo-av": "~15.0.1",
    "expo-blur": "~14.0.1",
    "expo-build-properties": "~0.13.1",
    "expo-clipboard": "~7.0.0",
    "expo-constants": "~17.0.3",
    "expo-dev-client": "^5.0.8",
    "expo-font": "~13.0.2",
    "expo-image": "~2.0.3",
    "expo-keep-awake": "~14.0.1",
    "expo-linear-gradient": "~14.0.1",
    "expo-linking": "~7.0.3",
    "expo-modules-core": "~2.1.2",
    "expo-navigation-bar": "~4.0.6",
    "expo-network": "~7.0.4",
    "expo-splash-screen": "^0.29.18",
    "expo-status-bar": "~2.0.0",
    "expo-system-ui": "~4.0.6",
    "expo-updates": "~0.26.10",
    "lottie-react-native": "^7.1.0",
    "react": "18.3.1",
    "react-native": "0.76.5",
    "react-native-animated-dots-carousel": "^1.0.2",
    "react-native-ble-plx": "^2.0.3",
    "react-native-device-info": "^10.14.0",
    "react-native-dotenv": "^3.4.11",
    "react-native-elements": "^3.4.3",
    "react-native-gesture-handler": "2.20.2",
    "react-native-get-random-values": "~1.11.0",
    "react-native-google-fit": "^0.19.1",
    "react-native-linear-gradient": "^2.8.3",
    "react-native-modal": "^13.0.1",
    "react-native-reanimated": "3.16.6",
    "react-native-reanimated-carousel": "^3.5.1",
    "react-native-safe-area-context": "4.12.0",
    "react-native-screens": "~4.4.0",
    "react-native-svg": "15.8.0",
    "react-native-svg-transformer": "^1.5.0",
    "react-native-system-navigation-bar": "^2.6.4",
    "react-native-toast-message": "^2.2.1",
    "react-native-toast-notifications": "^3.4.0",
    "react-native-watch-connectivity": "^1.1.0",
    "react-persist": "^1.0.2",
    "react-redux": "^8.1.3",
    "redux-persist": "^6.0.0",
    "reflect-metadata": "^0.1.14",
    "styled-components": "^6.1.13"
  },
  "devDependencies": {
    "@babel/core": "^7.26.0",
    "@babel/plugin-transform-runtime": "^7.25.9",
    "@babel/runtime": "^7.23.0",
    "@types/react": "~18.3.18",
    "babel-plugin-macros": "^3.1.0",
    "babel-preset-expo": "^12.0.4",
    "eslint": "^8.57.1",
    "eslint-config-universe": "^12.1.0",
    "prettier": "^3.4.2",
    "rimraf": "^5.0.10",
    "typescript": "^5.7.2"
  },
  "private": true
}

当前使用expo-modules-core@2.1.2和expo@52.0.23。


解决方案

1. 清理缓存并重装依赖

  • 删除node_modules目录和锁文件(package-lock.json/yarn.lock)
  • 重新安装依赖:
npm install
# 或 yarn install
  • 清除Metro缓存后重启项目:
npx expo start --clear
# 或 npx react-native start --reset-cache

2. 确保版本兼容性

Expo 52要求expo-modules-core版本为~2.1.0,当前版本兼容,但可尝试重新指定版本:

npm install expo-modules-core@~2.1.0

3. 修复裸项目原生配置

  • 重新生成原生项目配置:
npx expo prebuild
  • 清理Android构建缓存:
cd android && ./gradlew clean && cd ..
  • 重新运行Android项目:
npx react-native run-android

4. 检查Babel配置

确保babel.config.js使用正确的预设:

module.exports = {
  presets: ['babel-preset-expo'],
};

5. 验证Metro配置

如果自定义了metro.config.js,确保未排除expo-modules-core,使用默认配置即可:

const { getDefaultConfig } = require('expo/metro-config');

const config = getDefaultConfig(__dirname);

module.exports = config;

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.15 03:27:07