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

Expo+React Native项目报错:无法解析../Utilities/Platform路径

解决Expo + React Native中"Unable to resolve '../Utilities/Platform'"报错

我在使用Expo和React Native开发应用时遇到了以下报错:

Unable to resolve "../Utilities/Platform" from "node_modules\react-native\Libraries\ReactPrivate\ReactNativePrivateInterface.js"

注:此错误并非由react-native-maps导致(已有相关解决方案),我的package.json依赖配置如下:

"dependencies": {
    "@expo/metro-runtime": "~3.2.3",
    "@react-native-async-storage/async-storage": "1.23.1",
    "@react-navigation/native": "^6.1.18",
    "@react-navigation/native-stack": "^6.11.0",
    "axios": "^1.7.7",
    "expo": "~51.0.28",
    "expo-clipboard": "~6.0.3",
    "expo-crypto": "~13.0.2",
    "expo-device": "~6.0.2",
    "expo-font": "~12.0.10",
    "expo-image": "~1.12.15",
    "expo-localization": "~15.0.3",
    "expo-status-bar": "~1.12.1",
    "expo-system-ui": "~3.0.7",
    "firebase": "^10.13.1",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-native": "0.74.5",
    "react-native-dotenv": "^3.4.11",
    "react-native-pager-view": "6.3.0",
    "react-native-safe-area-context": "4.10.5",
    "react-native-screens": "3.31.1",
    "react-native-svg": "15.2.0",
    "react-native-web": "~0.19.10"
  },

可行的解决方案

1. 清除缓存重启Metro

直接执行命令强制清除缓存,让Metro重新解析所有依赖路径:

npx expo start --clear

2. 重新安装依赖

删除现有依赖文件后重新安装,修复可能的依赖损坏问题:

rm -rf node_modules package-lock.json yarn.lock
npm install

(如果用yarn或pnpm,替换对应命令即可)

3. 检查Metro配置文件

确保metro.config.js使用Expo默认预设,避免自定义配置破坏核心模块解析:

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

const config = getDefaultConfig(__dirname);

module.exports = config;

4. 移除不必要的react-native-web依赖

如果不需要开发Web版本,直接卸载该依赖,避免Web与原生RN的文件结构冲突:

npm uninstall react-native-web

5. 排查第三方依赖兼容性

暂时移除react-native-dotenv这类可能引入旧版RN模块引用的依赖,验证是否是它导致的问题:

npm uninstall react-native-dotenv

如果问题解决,再更换该依赖的兼容版本或寻找替代方案。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 18:52:48