找不到模块'react-native-elements'。

问题描述 投票:1回答:1

刚刚创建了我的第一个React-Native应用程序,并使用以下方法添加了我的第一个库'react-native-elements'。

yarn add react-native-elements

包出现在我的node_modules文件夹和yarn.lock中,但是我收到了以下错误。

Cannot find module 'react-native-elements'

app.tsx

import { StyleSheet, Text, View } from 'react-native';
import { Button, FormLabel, FormInput, FormValidationMessage } from 'react-native-elements';



export default function App() {
  return (
    <View style={styles.container}>
      <FormLabel>Name</FormLabel>
      <FormInput />
      <FormValidationMessage>Error message</FormValidationMessage>
      <Button>Send</Button>
    </View>
  );
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    backgroundColor: '#fff',
    alignItems: 'center',
    justifyContent: 'center',
  },
});

包裹.json

{
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~37.0.3",
    "react": "~16.9.0",
    "react-dom": "~16.9.0",
    "react-native": "https://github.com/expo/react-native/archive/sdk-37.0.1.tar.gz",
    "react-native-elements": "^2.0.2",
    "react-native-screens": "~2.2.0",
    "react-native-web": "~0.11.7"
  },
  "devDependencies": {
    "@babel/core": "^7.8.6",
    "@types/react": "~16.9.23",
    "@types/react-native": "~0.61.17",
    "babel-preset-expo": "~8.1.0",
    "typescript": "~3.8.3"
  },
  "private": true
}
react-native yarn
1个回答
2
投票

https:/react-native-elements.github.ioreact-native-elementsdocstroubleshooting.html。你可以试试这个吗?

yarn - rm -rf node_modules && yarn && yarn add react-native-elements
npm start -- --reset-cache
© www.soinside.com 2019 - 2024. All rights reserved.