@react-navigation/native-stack could not be found within the project or in these directories:

0

Dostaje błąd przy uruchomieniu projektu

import { StyleSheet, Text, View } from 'react-native';
import AppNavigator from './componets/AppNavigator';

export default function App() {
  return (
    <View style={styles.container}>
      <AppNavigator></AppNavigator>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});
import { StatusBar } from 'expo-status-bar';
import { NavigationContainer } from '@react-navigation/native';
import { CreateNativeStackNavigator } from '@react-navigation/native-stack';
import LoginView from "../screen/LoginView";

const Stack = CreateNativeStackNavigator();


const AppNavigator = () => (
    <>
    <StatusBar style='auto'/>
    <NavigationContainer>
      <Stack.Navigator initialRouteName="Login">
            <Stack.Screen name="Login" component={LoginView}/>
        </Stack.Navigator>
    </NavigationContainer>
    </>
)

export default AppNavigator;
iOS Bundling failed 45ms
Unable to resolve module @react-navigation/native-stack from xxxxx/componets/AppNavigator.js: @react-navigation/native-stack could not be found within the project or in these directories:
  node_modules
  ../../../../../node_modules
  1 | import { StatusBar } from 'expo-status-bar';
  2 | import { NavigationContainer } from '@react-navigation/native';
> 3 | import { CreateNativeStackNavigator } from '@react-navigation/native-stack';
    |                                             ^
  4 | import LoginView from "../screen/LoginView";
  5 |
  6 | const Stack = CreateNativeStackNavigator();
 "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "axios": "^0.27.2",
    "expo": "~45.0.0",
    "expo-status-bar": "~1.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-navigation-stack": "^2.10.4",
    "react-native-web": "0.17.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  },
  "private": true
}

0

https://reactnavigation.org/docs/native-stack-navigator/

Mało korzystałem z React Native, ale wydaje mi się, że jest to osobna biblioteka, więc musisz ją zainstalować

npm install @react-navigation/native-stack

0

miałem dodana to bibliotekę za to teraz dostaje

TypeError: (0, _nativeStack.CreateNativeStackNavigator) is not a function. (In '(0, _nativeStack.CreateNativeStackNavigator)()', '(0, _nativeStack.CreateNativeStackNavigator)' is undefined)
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:95:4 in reportException
at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141: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:203:6 in guardedLoadModule
at http://192.168.1.113:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:131599: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:95:4 in reportException
    at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141: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
0
TakMaszRacje napisał(a):

miałem dodana to bibliotekę za to teraz dostaje

TakMaszRacje napisał(a):
{
  "dependencies": {
    "axios": "^0.27.2",
    "expo": "~45.0.0",
    "expo-status-bar": "~1.3.0",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-navigation-stack": "^2.10.4",
    "react-native-web": "0.17.7"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9"
  }
}

U siebie lokalnie może miałeś, nie chcę przeczyć, że nie, ale na forum tego nie wrzuciłeś, bo w tym package.json na pewno jej nie ma :p

Jeśli chodzi Ci przypadkiem o react-navigation-stack (https://www.npmjs.com/package/react-navigation-stack) to jest to coś innego niż @react-navigation/native-stack (https://www.npmjs.com/package/@react-navigation/native-stack).

TakMaszRacje napisał(a):

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:95:4 in reportException
    at node_modules/react-native/Libraries/Core/ExceptionsManager.js:141: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

Musisz posprawdzać w internecie jak można to naprawić (https://stackoverflow.com/questions/62649381/invariant-violation-main-has-not-been-registered) i któraś z opcji może zadziała.

1 użytkowników online, w tym zalogowanych: 0, gości: 1