"TypeError: (0, _native.createNavigatorFactory) is not a function." after upgrading Expo
"TypeError: (0, _native.createNavigatorFactory) is not a function." after upgrading Expo
我最近将 Expo 升级到 ^44.0.0 并收到此错误:
TypeError: (0, _native.createNavigatorFactory) 不是函数。 (在“(0,_native.createNavigatorFactory)(StackNavigator)”中,“(0,_native.createNavigatorFactory)”未定义)
我到处搜索并更新了所有内容,但我似乎无法让它工作。我做错了什么?
这是我的package.json
内容:
"@react-navigation/core": "^6.1.1",
"@react-navigation/native": "^3.8.4",
"@react-navigation/native-stack": "^6.5.0",
"@react-navigation/stack": "^5.14.2",
"core-js": "^3.4.8",
"expo": "^44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-44.0.0.tar.gz",
"react-native-gesture-handler": "~2.1.0",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
这是我的 App.js
:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/stack';
import HomeScreen from './HomeScreen';
import AddTaskScreen from './AddTaskScreen';
import AddWorkTimeScreen from './AddWorkTimeScreen';
const Stack = createNativeStackNavigator();
export default class App extends React.Component {
render(){
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen options={{headerShown: false}} name="Home" component={HomeScreen}/>
<Stack.Screen name="AddTask" component={AddTaskScreen} options={{ title: 'Task' }}/>
<Stack.Screen name="AddWorkTime" component={AddWorkTimeScreen} options={{ title: 'Work Times' }} />
</Stack.Navigator>
</NavigationContainer>
);
}
}
我也更新了 typescript 到 ^4.6.2
问题出在您的@react-navigation/native 版本上,即 ^3.8.4。我看到您正在使用 5.x 或 6.x 版本来处理其他所有内容,因此我建议将 @react-navigation/native 升级到 6.0.0。这应该可以修复错误。
我还建议将所有 5.x 版本更新到 6.x 版本,但这是您的选择。
我最近将 Expo 升级到 ^44.0.0 并收到此错误: TypeError: (0, _native.createNavigatorFactory) 不是函数。 (在“(0,_native.createNavigatorFactory)(StackNavigator)”中,“(0,_native.createNavigatorFactory)”未定义)
我到处搜索并更新了所有内容,但我似乎无法让它工作。我做错了什么?
这是我的package.json
内容:
"@react-navigation/core": "^6.1.1",
"@react-navigation/native": "^3.8.4",
"@react-navigation/native-stack": "^6.5.0",
"@react-navigation/stack": "^5.14.2",
"core-js": "^3.4.8",
"expo": "^44.0.0",
"expo-status-bar": "~1.2.0",
"react": "17.0.1",
"react-dom": "17.0.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-44.0.0.tar.gz",
"react-native-gesture-handler": "~2.1.0",
"react-native-safe-area-context": "3.3.2",
"react-native-screens": "~3.10.1",
这是我的 App.js
:
import { StatusBar } from 'expo-status-bar';
import React from 'react';
import { StyleSheet, Text, View, } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createNativeStackNavigator } from '@react-navigation/stack';
import HomeScreen from './HomeScreen';
import AddTaskScreen from './AddTaskScreen';
import AddWorkTimeScreen from './AddWorkTimeScreen';
const Stack = createNativeStackNavigator();
export default class App extends React.Component {
render(){
return (
<NavigationContainer>
<Stack.Navigator>
<Stack.Screen options={{headerShown: false}} name="Home" component={HomeScreen}/>
<Stack.Screen name="AddTask" component={AddTaskScreen} options={{ title: 'Task' }}/>
<Stack.Screen name="AddWorkTime" component={AddWorkTimeScreen} options={{ title: 'Work Times' }} />
</Stack.Navigator>
</NavigationContainer>
);
}
}
我也更新了 typescript 到 ^4.6.2
问题出在您的@react-navigation/native 版本上,即 ^3.8.4。我看到您正在使用 5.x 或 6.x 版本来处理其他所有内容,因此我建议将 @react-navigation/native 升级到 6.0.0。这应该可以修复错误。
我还建议将所有 5.x 版本更新到 6.x 版本,但这是您的选择。