undefined不是一个函数(评估'react DevTools.connect DevTools')

时间:2019-01-04 14:31:36

标签: react-native react-navigation

我实际上正在使用react-native学习导航工具。我尝试了文档https://reactnavigation.org/docs/en/hello-react-navigation.html中的示例。我不知道为什么会显示此错误

enter image description here

这是代码:

     import React from 'react';
    import { View, Text, Button } from 'react-native';
    import { createAppContainer, createStackNavigator, StackActions, 
    NavigationActions } from 'react-navigation'; // Version can be specified 
    in package.json

     class HomeScreen extends React.Component {
      render() {
        return (
      <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' 
       }}>
      <Text>Home Screen</Text>
      <Button
       title="Go to Details"
       onPress={() => {
        this.props.navigation.dispatch(StackActions.reset({
          index: 0,
          actions: [
            NavigationActions.navigate({ routeName: 'Details' })
          ],
        }))
      }}
            />
          </View>
         );
         }  
          }

  class DetailsScreen extends React.Component {
  render() {
  return (
   <View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' 
    }}>
    <Text>Details Screen</Text>
  </View>
  );
 }  
 }

const AppNavigator = createStackNavigator({
Home: {
 screen: HomeScreen,
  },
  Details: {
  screen: DetailsScreen,
 },
}, {
  initialRouteName: 'Home',
 });

export default createAppContainer(AppNavigator);

您知道如何解决此问题吗?

2 个答案:

答案 0 :(得分:0)

在具有React-Native 0.57.8的Mac上,我删除了node_modules和package.lock.json,然后将react-devtools-core@3.4.2放在devDependencies下。运行npm installreact-native run-ios并成功。根据React DevTools的贡献者,基于以下线程,此问题已得到解决:https://github.com/facebook/react-native/issues/22865

答案 1 :(得分:0)

在这里解决:https://github.com/facebook/react-native/issues/22863

回滚到react-devtools-core@3.4.2对我有用:

纱线添加--dev react-devtools-core@3.4.3 要么 npm install --save-dev react-devtools-core@3.4.3