Expo应用启动报错求助:依赖异常导致无法打开
Expo应用启动失败:依赖与路由模块问题
我的Expo应用此前运行正常,现在启动时抛出错误无法打开,推测是依赖包变更导致。具体报错信息如下:
› Open in the web browser... (node:5684) [DEP_WEBPACK_DEV_SERVER_CONSTRUCTOR] DeprecationWarning: Using 'compiler' as the first argument is deprecated. Please use 'options' as the first argument and 'compiler' as the second argument. (Use `node --trace-deprecation ...` to show where the warning was created) (node:5684) [DEP_WEBPACK_DEV_SERVER_LISTEN] DeprecationWarning: 'listen' is deprecated. Please use the async 'start' or 'startCallback' method. › Press ? │ show all commands › Open in the web browser... › Press ? │ show all commands WARNING in ./node_modules/expo-router/src/exports.ts:26 export 'ErrorBoundaryProps' (reexported as 'ErrorBoundaryProps') was not found in './views/Try' (possible exports: Try) 24 | export { ExpoRoot } from "./ExpoRoot"; 25 | export { Unmatched } from "./views/Unmatched"; > 26 | export { ErrorBoundaryProps } from "./views/Try"; 27 | export { ErrorBoundary } from "./views/ErrorBoundary"; 28 | 29 | // Platform ERROR in ./node_modules/expo-router/_ctx.web.tsx:1:19 Module not found: Can't resolve '..\..\app' > 1 | export const ctx = require.context( | ^ 2 | process.env.EXPO_ROUTER_APP_ROOT!, 3 | true, 4 | /.*/, web compiled with 1 error and 1 warning
项目的package.json配置:
{ "name": "logintest", "version": "1.0.0", "main": "expo-router/entry", "scripts": { "start": "expo start", "android": "expo start --android", "ios": "expo start --ios", "web": "expo start --web" }, "dependencies": { "@expo/webpack-config": "^19.0.0", "@react-navigation/bottom-tabs": "^6.5.11", "@react-navigation/drawer": "^6.6.6", "@types/react": "~18.2.14", "expo": "~49.0.13", "expo-constants": "~14.4.2", "expo-linking": "~5.0.2", "expo-router": "^2.0.0", "expo-status-bar": "~1.6.0", "react": "18.2.0", "react-native": "0.72.6", "react-native-gesture-handler": "~2.12.0", "react-native-popup-menu": "^0.16.1", "react-native-reanimated": "~3.3.0", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-svg": "13.9.0", "react-native-web": "~0.19.6", "typescript": "^5.1.3" }, "devDependencies": { "@babel/core": "^7.20.0", "@types/webpack-env": "^1.18.4", "react-native-svg-transformer": "^1.1.0", "sharp-cli": "^2.1.0", "source-map-support": "^0.5.21" }, "private": true }
已尝试更换不同Node版本、调整依赖包版本,但问题仍未解决,寻求帮助。
解决方案
锁定expo-router兼容版本:expo-router v2.0.0与expo 49存在兼容性问题,将
package.json中的expo-router版本改为"expo-router": "~2.0.10"(适配expo 49的稳定版本),避免使用^自动拉取不兼容的更新。清理缓存并重装依赖:
- 删除node_modules目录:
rm -rf node_modules(Windows系统执行rmdir /s /q node_modules) - 删除package-lock.json:
rm package-lock.json - 清除Expo缓存:
expo r -c - 重新安装依赖:
npm install
- 删除node_modules目录:
验证路由目录结构:确保项目根目录存在
app文件夹,且至少包含一个路由文件(如app/index.tsx)。expo-router依赖该目录生成路由上下文,缺失会导致Can't resolve '..\..\app'错误。适配webpack配置版本:将
@expo/webpack-config版本锁定为"@expo/webpack-config": "~19.0.1",与expo 49保持兼容,消除webpack deprecation警告。
内容的提问来源于stack exchange,提问作者Felix Bolongaro
相关产品推荐
相关产品推荐

