【问题标题】:How to fix util could not be found in React Native?如何修复在 React Native 中找不到 util?
【发布时间】:2020-02-23 12:52:00
【问题描述】:

我是本机反应的新手,我创建了一个用于在屏幕之间导航的示例应用程序,但我遇到了一些问题。我已附上屏幕截图。

我在 App.js 中使用过的代码

import React from 'react';
import {Text, View } from 'react-native';

import { StackNavigator } from 'react-navigation';
import  FirstScreen  from './screens/FirstScreen'
import  SecondScreen  from './screens/SecondScreen'

const Navigation = StackNavigator({
First: {screen: FirstScreen},
Second: {screen: SecondScreen}
});

export default Navigation; // Export your root navigator as the root component

第二屏代码:

import React from 'react';
import {Text, View, Button} from 'react-native';
const util = require('util');

export default class SecondScreen extends React.Component {
static navigationOptions = {
    title: 'Second screen',
};

render() {
    console.log("this.props.navigation.state = " + util.inspect(this.props.navigation.state, false, null));
    var {params} = this.props.navigation.state;
    return (
        <View>
            <Text>This is screen 2</Text>
            <Text>Params from screen1 : {params.name}, email = {params.email}</Text>
        </View>
    );
}
  }

这些代码是我从 github 得到的。

【问题讨论】:

  • 贴出SecondScreen的代码
  • oleg 你现在可以检查一下吗。
  • util 是 nodejs 中的内置模块。我不使用 React Native,所以它也有吗?在您的代码中,它仅使用util.inspect。所以只需将其更改为控制台日志。
  • Keith 我对 react native 了解不多,但我发现 util build 在 node_module 中。
  • 尝试:npm install util --save

标签: javascript react-native react-native-android


【解决方案1】:

请参阅以下链接。您必须清除缓存并再次运行。

How to clear react-native cache?

在第二个屏幕代码中可能会出现路径问题或某些错误。在第二个屏幕上创建一个简单的 hello world。

【讨论】:

    猜你喜欢
    • 2018-12-21
    • 1970-01-01
    • 2022-06-19
    • 2022-09-29
    • 1970-01-01
    • 2022-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多