首页 > 解决方案 > TypeError:尝试更改不可配置属性的 getter

问题描述

我正在尝试在我的 Visual Studio 代码上运行以下代码,并npm start在我的终端上运行时在 Expo 客户端中出现以下错误。

import { createStackNavigator, createAppContainer } from 'react-navigation';
import CategoriesScreen from '../screens/CategoriesScreen';
import CategoryItemsScreen from '../screens/CategoryItemsScreen';
 
const ItemsNavigator = createStackNavigator({
    Categories: CategoriesScreen,
    CategoryItems: {
        screen: CategoryItemsScreen
    }
});
 
export default createAppContainer(ItemsNavigator);

下面是我得到的错误

TypeError: Attempting to change the getter of an unconfigurable property.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError
at node_modules/metro-runtime/src/polyfills/require.js:204:6 in guardedLoadModule
at http://192.168.0.109:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&minify=false:126726:3 in global code
 
Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called.
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19 in handleException
at node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in handleError
at node_modules/@react-native/polyfills/error-guard.js:49:36 in ErrorUtils.reportFatalError

我的 package.json 如下

  "dependencies": {
    "@react-native-community/masked-view": "^0.1.11",
    "@react-navigation/native": "^6.0.6",
    "expo": "~43.0.0",
    "expo-app-loading": "~1.2.1",
    "expo-font": "~10.0.3",
    "expo-status-bar": "~1.1.0",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.2",
    "react-native-gesture-handler": "~1.10.2",
    "react-native-reanimated": "~2.2.0",
    "react-native-safe-area-context": "^3.3.2",
    "react-native-screens": "~3.8.0",
    "react-native-web": "0.17.1",
    "react-navigation": "^4.4.4",
    "react-navigation-stack": "^2.10.4"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

有人可以帮忙吗。

标签: react-nativeexpo

解决方案


将 NodeJS 降级到 14.18.1 版本。我做到了,这个错误消失了


推荐阅读