Why do I keep getting the following error : "Unable to resolve module @react-navigation-stack"?
Why do I keep getting the following error : "Unable to resolve module @react-navigation-stack"?
我正在使用 expo
在 React Native 中构建一个项目。我一直收到同样的错误:enter image description here
这是我的 App.js
:
import 'react-native-gesture-handler';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createStackNavigator } from '@react-navigation-stack';
import Home from './src/components/Home.js';
const Stack = createStackNavigator();
function myStack() {
return (
<Stack.Navigator>
<Stack.Sreen
name="Home"
component={Home}
/>
</Stack.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<myStack/>
</NavigationContainer>
);
}
这是我的一小部分 package.json
:
"dependencies": {
"@react-navigation/core": "react-navigation/core",
"@react-navigation/native": "react-navigation/native",
"expo": "~42.0.1",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-gesture-handler": "~1.10.2",
"react-native-web": "~0.13.12",
"react-navigation": "^4.4.4",
"react-navigation-stack": "^2.10.4"
},
你能帮我理解为什么我安装了 react-navigation-stack
后仍然出现这个错误吗?
请阅读 react-navigation
v4.x、react-navigation-stack 的说明。
去掉@符号,需要这样使用:
import { createStackNavigator } from 'react-navigation-stack';
要安装 运行 expo
的以下命令:
expo install react-navigation-stack
希望这对你有用。
您输入的包名有误。是 @react-navigation/stack
,不是 @react-navigation-stack
我正在使用 expo
在 React Native 中构建一个项目。我一直收到同样的错误:enter image description here
这是我的 App.js
:
import 'react-native-gesture-handler';
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
import { createStackNavigator } from '@react-navigation-stack';
import Home from './src/components/Home.js';
const Stack = createStackNavigator();
function myStack() {
return (
<Stack.Navigator>
<Stack.Sreen
name="Home"
component={Home}
/>
</Stack.Navigator>
);
}
export default function App() {
return (
<NavigationContainer>
<myStack/>
</NavigationContainer>
);
}
这是我的一小部分 package.json
:
"dependencies": {
"@react-navigation/core": "react-navigation/core",
"@react-navigation/native": "react-navigation/native",
"expo": "~42.0.1",
"expo-status-bar": "~1.0.4",
"react": "16.13.1",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz",
"react-native-gesture-handler": "~1.10.2",
"react-native-web": "~0.13.12",
"react-navigation": "^4.4.4",
"react-navigation-stack": "^2.10.4"
},
你能帮我理解为什么我安装了 react-navigation-stack
后仍然出现这个错误吗?
请阅读 react-navigation
v4.x、react-navigation-stack 的说明。
去掉@符号,需要这样使用:
import { createStackNavigator } from 'react-navigation-stack';
要安装 运行 expo
的以下命令:
expo install react-navigation-stack
希望这对你有用。
您输入的包名有误。是 @react-navigation/stack
,不是 @react-navigation-stack