javascript - React-Native / Expo 项目中的“无法连接到 Metro 服务器”
问题描述
我目前正在尝试使用 React-Native 和 Expo 使用 MapView 组件构建一个小东西。
当我在 Expo Go 中扫描 Expo QR 码时,Google 地图完美显示在我的手机上,但我只是稍微修改了我的代码,只是修改了地图窗口的尺寸 - 这可能是造成这种情况的原因,因为我这样做可能是错的,尽管我非常怀疑。
到目前为止,这是我的代码(我只使用了 App.js 文件):
import { StatusBar } from 'expo-status-bar';
import * as React from 'react';
import { StyleSheet, Text, View, Dimensions } from 'react-native';
import MapView from 'react-native-maps';
export default function App() {
return (
<View style={styles.container}>
<MapView style={styles.map} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
map: {
width: Dimensions.get('window').width,
height: Dimensions.get('window' - 10).height,
},
});
我的终端中显示的错误是:
Cannot connect to the Metro server.
请尝试以下方法来解决此问题:
- 确保 Metro 服务器正在同一网络上运行并可用
- 确保您的设备/模拟器已连接到您的机器并启用了 USB 调试 - 运行“adb devices”以查看已连接设备的列表
- 如果您在连接到同一台机器的物理设备上,请运行“adb reverse tcp:8081 tcp:8081”以转发来自您设备的请求
- 如果您的设备在同一个 Wi-Fi 网络上,请将“开发设置”中的“调试服务器主机和设备端口”设置为您机器的 IP 地址和本地开发服务器的端口 - 例如 10.0.1.1:8081
网址:10.1.5.81:19000
解决方案
推荐阅读
- c# - 尝试使用 Win32_NetworkAdapterConfiguration 在 c# 中更改网络适配器的网络设置(DNS),但我看不到我做错了什么
- python - 将列附加到 Pandas 数据框
- python - Python maplotlib PNG 和 FPDF
- python - 为什么 Python 多处理不能在我的 PC 上运行?
- node.js - AWS NodeJS Lambda:将事件数据对象作为参数传递给需要模块
- c++ - 如何使用 ITK 将 PNG 转换为 PyTorch 的张量
- c# - 如何在检查了私有和公共配置文件的情况下将授权应用程序添加到 Windows 防火墙?
- r - 将 str_wrap() 与 expression() 结合使用以获得自定义标题以适合 ggplot2 中的绘图
- powerbi - power bi 折线图上的降序图例
- mysql - 如何更改表(创建/更改)以便在不使用 INSERT、UPDATE 查询整个表时显示计算的“平均分数”字段