我安装了 react-native
和全局 cli。
但是当我运行 npm start
时,出现此错误:
Cannot find module 'react-native'
这是我的 App.js
文件。谢谢...
import React from "react";
import { SafeAreaView, View, Text } from "react-native";
function App() {
return (
<SafeAreaView
style={{
flex: 1,
alignItems: "center",
justifyContent: "center",
}}
>
<View
style={{
flex: 1,
alignItems: "center",
justifyContent: "center",
}}
>
<View style={{ flex: 3 }}>
<Text>Kayıt Listesi</Text>
</View>
</View>
</SafeAreaView>
);
}
export default App;
最佳答案
执行以下步骤:
- 删除您的
node_modules
目录。 - 运行
npm install
。 - 运行
npm start
。
命令npm install
将项目所需的所有内容安装到node_modules
目录中。
如果这没有帮助,请尝试通过执行命令npm install react-native --save
来单独添加react-native
。
使用 npm init
初始化新项目通常是一个好主意,它会创建一个 package.json
文件,其中 npm
存储所有已安装软件包的名称和版本。
编辑:在我们调查了整个堆栈跟踪之后,显然我们需要通过命令 npm install react- 安装
.react-native-web
原生网络
关于react-native - React Native "Cannot find module ' react-native'"问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71166179/