首页 > 解决方案 > React Native 项目返回“TypeError: undefined is not an object”

问题描述

我正在开发一个 React Native 项目,我收到了这个错误

TypeError:未定义不是对象(评估'_reactNative.Animated.Text.propTypes.style')

我该如何解决这个错误?

这是 App.js

import React from 'react';
import {View, TextInput, Text, StyleSheet} from 'react-native';
import {TextField} from 'react-native-material-textfield';

const App = () => {
  return (
    <View style={styles.container}>
      <Text style={styles.heading}>Billing Information</Text>
      <Text style={styles.paragraph}>Name</Text>
      <TextInput style={styles.input} placeholder="Mark" />
      <TextField label="Email" />
    </View>
  );
};

const styles = StyleSheet.create({
  container: {
    marginTop: 50,
    padding: 20,
    color: '#ff0000',
  },

  heading: {
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'left',
    color: '#ff0000',
  },

  paragraph: {
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'left',
    color: '#0000ff',
    backgroundColor: '#32CD32',
  },

  input: {
    fontSize: 18,
    fontWeight: 'bold',
    textAlign: 'left',
    color: '#0000ff',
  },
});

export default App;
`````````

This is package.json
```````
{
  "name": "form",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "android": "react-native run-android",
    "ios": "react-native run-ios",
    "start": "react-native start",
    "test": "jest",
    "lint": "eslint ."
  },
  "dependencies": {
    "react": "16.11.0",
    "react-native": "0.62.2",
    "react-native-elements": "^2.0.0",
    "react-native-form-builder": "^1.0.16",
    "react-native-material-textfield": "^0.16.1"
  },
  "devDependencies": {
    "@babel/core": "7.9.6",
    "@babel/runtime": "7.9.6",
    "@react-native-community/eslint-config": "0.0.5",
    "babel-jest": "24.9.0",
    "eslint": "6.8.0",
    "jest": "24.9.0",
    "metro-react-native-babel-preset": "0.58.0",
    "react-test-renderer": "16.11.0"
  },
  "jest": {
    "preset": "react-native"
  }
}

标签: react-native

解决方案


你需要Animatedreact-native下面这样导入

import {View, TextInput, Animated, Text, StyleSheet} from 'react-native';

推荐阅读