嗨,我正在使用expo SDK 50版本和react-native,所以每当我尝试在expo go应用程序上打开项目时,都会出现错误,它会向我显示类似的错误
未捕获的错误
“main”尚未注册。如果出现以下情况,就会发生这种情况: * Metro(本地开发服务器)从错误的文件夹运行。检查Metro是否正在运行,在当前项目中停止并重新启动它。
这是App.js代码
import React, { useEffect } from "react";
import messaging from "@react-native-firebase/messaging";
import analytics from "@react-native-firebase/analytics";
import AppNavigator from "./Source/Navigation/AppNavigator";
import { Provider } from "react-redux";
import store from "./Source/store";
import { FIREBASE_TOPIC_NAME } from "./Source/Constant/ConstantApi";
import { PermissionsAndroid } from "react-native";
import { GlobalStateProvider } from "./Source/Context/GlobalStateContext";
export default function App() {
useEffect(() => {
const requestUserPermission = async () => {
try {
// Request notification permission
const granted = await PermissionsAndroid.request(
PermissionsAndroid.PERMISSIONS.POST_NOTIFICATIONS,
{
title: "Notification Permission",
message: "This app needs access to send you notifications.",
buttonNeutral: "Ask Me Later",
buttonNegative: "Cancel",
buttonPositive: "OK",
}
);
if (granted === PermissionsAndroid.RESULTS.GRANTED) {
console.log("Notification permission granted");
} else {
console.log("Notification permission denied");
}
// Request Firebase Cloud Messaging permission
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log("Authorization status:", authStatus);
}
} catch (error) {
console.error(error);
}
};
const subscribeToMessagingEvents = async () => {
try {
// Subscribe to FIREBASE_TOPIC_NAME topic
await messaging().subscribeToTopic(FIREBASE_TOPIC_NAME);
console.log(`Subscribed to ${FIREBASE_TOPIC_NAME} topic successfully`);
// Print FCM token
const printFCMToken = async () => {
try {
const token = await messaging().getToken();
console.log("FCM Token:", token);
} catch (error) {
console.error(error);
}
};
printFCMToken();
return () => {
messageSubscription();
};
} catch (error) {
console.error(error);
}
};
// Execute the initialization functions
requestUserPermission();
const unsubscribe = subscribeToMessagingEvents();
// Log event for app initialization
analytics().logEvent("app_initialized");
return () => {
unsubscribe();
};
}, []);
return (
<GlobalStateProvider>
<Provider store={store}>
<AppNavigator />
</Provider>
</GlobalStateProvider>
);
}
但是当我使用react-native默认模板时
import React from 'react';
import { Text, View } from 'react-native';
export default function App() {
return (
<View style={{ flex: 1, justifyContent: 'center', alignItems: 'center' }}>
<Text>Hello, Expo!</Text>
</View>
);
}
请有人帮我解决这个问题
我已经尝试了 stackoverflow 上可用的所有命令,但它在 expo go 上仍然不起作用。
我正在尝试为我的问题找到解决方案
未捕获的错误
“main”尚未注册。如果出现以下情况,就会发生这种情况: * Metro(本地开发服务器)从错误的文件夹运行。检查Metro是否正在运行,在当前项目中停止并重新启动它。
我也遇到了同样的错误,并且花了 5 天的时间才修复这个问题。 我正在使用 Expo SDK 51。此链接中的解决方案帮助我解决了错误:registerRootComponent。
Expo SDK 需要不同的方式来注册RootComponent。
import { registerRootComponent } from 'expo';
import { View } from 'react-native';
function App() {
return <View />;
}
registerRootComponent(App);