0

我正在使用 Expo 和 React Native 制作一个移动应用程序。我想将 React Native Debugger 集成到我的项目中以进行反应,但我遇到了麻烦。

专门连接到反应开发工具失败。我正在使用 Expo 客户端(通过 wifi 连接的真实设备)。我阅读了React Native Debugger's connect to React not working with Expo Client,但我使用的是更新版本的 react native 调试器,所以这个问题对我没有帮助。在文件 node_modules/react-native/Libraries/Core/Devtools/setupDevtools.js 中,我将主机变量更改为我的本地 IP,但也没有用。

  // Get hostname from development server (packager)
  const devServer = getDevServer();
  /*
  const host = devServer.bundleLoadedFromServer
    ? devServer.url.replace(/https?:\/\//, '').split(':')[0]
    : 'localhost';
  */
   const host = '192.168.0.108'
  // Read the optional global variable for backward compatibility.
  // It was added in https://github.com/facebook/react-native/commit/bf2b435322e89d0aeee8792b1c6e04656c2719a0.
  const port =
    window.__REACT_DEVTOOLS_PORT__ != null
      ? window.__REACT_DEVTOOLS_PORT__
      : 8097;

  const WebSocket = require('../WebSocket/WebSocket');
  const ws = new WebSocket('ws://' + host + ':' + port);

  const viewConfig = require('../Components/View/ReactNativeViewViewConfig');
  reactDevTools.connectToDevTools({
    isAppActive,
    resolveRNStyle: require('../StyleSheet/flattenStyle'),
    nativeStyleEditorValidAttributes: Object.keys(
      viewConfig.validAttributes.style,
    ),
    websocket: ws,
  });
}

};

在项目根目录的 package.json 中,我有:

"dependencies": {
"expo": "~40.0.0",
"expo-status-bar": "~1.0.3",
"react": "16.13.1",
"react-devtools": "^3.6.3",
"react-dom": "16.13.1",
"react-native": "https://github.com/expo/react-native/archive/sdk-40.0.1.tar.gz",
"react-native-web": "~0.13.12"

},

4

0 回答 0