Expo项目运行yarn start报错:AppEntry.js出现Unexpected token 'export'
Expo项目启动报错:Android Bundling failed - Unexpected token 'export'
错误信息
执行yarn start启动应用时出现以下错误:
Android Bundling failed 449ms error: node_modules\expo\AppEntry.js: Unexpected token 'export'
相关文件内容
App.js
import React, { useState, useEffect } from "react"; import "react-native-gesture-handler"; import { createNativeStackNavigator } from "@react-navigation/native-stack"; import { NavigationContainer, DefaultTheme } from "@react-navigation/native"; import { onAuthStateChanged } from "firebase/auth"; import { auth } from "./config/firebaseConfig"; import { IntroductionAnimationScreen } from "./introduction_animation"; // screens import { PlantDetail, Welcome, Signup, Login, Profile, ChatBot, Settings, ExpertHome, CourseList, Cources, } from "./screens"; // Tab Navigator import Tabs from "./navigation/tabs"; // Font import { useFonts } from "expo-font"; const theme = { ...DefaultTheme, colors: { ...DefaultTheme.colors, border: "transparent", }, }; const Stack = createNativeStackNavigator(); const App = () => { const [user, setUser] = useState(null); useEffect(() => { const unsubscribe = onAuthStateChanged(auth, (authUser) => { if (authUser) { // User is signed in setUser(authUser); } else { // User is signed out setUser(null); } }); // Unsubscribe from the listener when the component unmounts return () => { unsubscribe(); }; }, []); const [loaded] = useFonts({ "Roboto-Light": require("./assets/fonts/Roboto-Light.ttf"), "Roboto-Black": require("./assets/fonts/Roboto-Black.ttf"), "Roboto-Bold": require("./assets/fonts/Roboto-Bold.ttf"), "Roboto-Regular": require("./assets/fonts/Roboto-Regular.ttf"), }); if (!loaded) { return null; } return ( <NavigationContainer theme={theme}> <Stack.Navigator screenOptions={{ headerShown: false, }} initialRouteName={user ? "HomeTabs" : "Welcome"} > {/* Tabs */} {user ? ( <> <Stack.Screen name="HomeTabs" component={Tabs} /> <Stack.Screen name="Profile" component={Profile} options={{ headerShown: false }} /> <Stack.Screen name="ChatBot" component={ChatBot} options={{ headerShown: false }} /> <Stack.Screen name="ExpertHome" component={ExpertHome} options={{ headerShown: false }} /> <Stack.Screen name="CourseList" component={CourseList} options={{ headerShown: false }} /> <Stack.Screen name="Cources" component={Cources} options={{ headerShown: false }} /> <Stack.Screen name="IntroductionAnimationScreen" component={IntroductionAnimationScreen} options={{ headerShown: false }} /> <Stack.Screen name="Settings" options={{ headerShown: false, cardStyleInterpolator: ({ current, next, layouts }) => { return { cardStyle: { transform: [ { translateX: current.progress.interpolate({ inputRange: [0, 1], outputRange: [layouts.screen.width, 0], }), }, ], }, overlayStyle: { opacity: current.progress.interpolate({ inputRange: [0, 1], outputRange: [0, 0.5], }), }, }; }, }} component={Settings} /> </> ) : ( <> {/* Screens */} <Stack.Screen name="Welcome" component={Welcome} options={{ headerShown: false }} /> <Stack.Screen name="Signup" component={Signup} options={{ headerShown: false }} /> <Stack.Screen name="Login" component={Login} options={{ headerShown: false }} /> </> )} <Stack.Screen name="PlantDetail" component={PlantDetail} options={{ headerShown: false }} /> </Stack.Navigator> </NavigationContainer> ); }; export default App;
package.json依赖配置
{ "dependencies": { "@expo/vector-icons": "^13.0.0", "@expo/webpack-config": "^19.0.0", "@google-ai/generativelanguage": "^1.1.0", "@react-native-async-storage/async-storage": "1.18.2", "@react-navigation/bottom-tabs": "^6.5.8", "@react-navigation/native": "^6.1.7", "@react-navigation/native-stack": "^6.9.13", "axios": "^1.5.0", "deprecated-react-native-prop-types": "^4.2.1", "dotenv": "^16.3.1", "expo": "~49.0.5", "expo-constants": "~14.4.2", "expo-font": "~11.4.0", "expo-image-picker": "~14.3.2", "expo-linear-gradient": "~12.3.0", "expo-status-bar": "~1.6.0", "firebase": "^10.3.1", "lodash": "^4.17.21", "nativewind": "^2.0.11", "postcss": "8.4.23", "prop-types": "*", "react": "18.2.0", "react-dom": "18.2.0", "react-native": "0.72.5", "react-native-gesture-handler": "~2.12.0", "react-native-gifted-chat": "^2.4.0", "react-native-heroicons": "^3.2.0", "react-native-modalize": "^2.1.1", "react-native-onboarding-swiper": "^1.2.0", "react-native-pager-view": "6.2.0", "react-native-progress": "^5.0.0", "react-native-progress-circle": "^2.1.0", "react-native-reanimated": "^3.5.4", "react-native-responsive-screen": "^1.4.2", "react-native-safe-area-context": "4.6.3", "react-native-screens": "~3.22.0", "react-native-splash-screen": "^3.3.0", "react-native-svg": "13.9.0", "react-native-tab-view": "^3.5.2", "react-native-vector-icons": "^10.0.0", "react-native-web": "~0.19.6" }, "devDependencies": { "@babel/core": "^7.20.0", "tailwindcss": "3.3.2", "typescript": "^5.1.3" } }
AppEntry.js
import registerRootComponent from 'expo/build/launch/registerRootComponent'; import App from '../../App'; registerRootComponent(App);
已尝试的解决方案
- 删除node_modules后执行
yarn install重新安装依赖 - 检查所有文件的import/export语法正确性
- 排查App.js中导入的所有页面组件的导出方式
可行解决方案建议
修正项目入口配置
错误提示指向node_modules/expo/AppEntry.js,说明打包时错误加载了Expo包内的入口文件,而非项目自身的入口。- 确认项目根目录存在正确的入口文件(
index.js或AppEntry.js),内容应为:import { registerRootComponent } from 'expo'; import App from './App'; registerRootComponent(App); - 打开
app.json,检查entryPoint字段,确保指向项目自身的入口文件(例如"./App.js"或"./index.js"),若没有该字段则添加。
- 确认项目根目录存在正确的入口文件(
检查Babel配置
项目根目录需有babel.config.js,确保配置正确:module.exports = function(api) { api.cache(true); return { presets: ['babel-preset-expo'], }; };若使用TypeScript,检查
tsconfig.json的compilerOptions,确保"module": "esnext"、"target": "es6",保证ES模块语法被正确转译。清理缓存并重新打包
执行expo r -c清除Expo缓存,再重新运行yarn start启动项目。排查依赖冲突
- 移除可能存在兼容性问题的第三方库,比如
react-native-splash-screen(Expo自带闪屏解决方案,第三方库易引发冲突),重新安装依赖后测试。 - 执行
yarn why expo查看Expo依赖版本是否存在冲突,确保所有Expo相关依赖版本与expo ~49.0.5匹配。
- 移除可能存在兼容性问题的第三方库,比如
内容的提问来源于stack exchange,提问作者Snehasish Konger
相关产品推荐
相关产品推荐

