首页 > 解决方案 > 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.

请尝试以下方法来解决此问题:

网址:10.1.5.81:19000

标签: javascriptreact-nativeexpo

解决方案


推荐阅读