【问题标题】:Cannot find module 'react-native-elements'找不到模块'react-native-elements'
【发布时间】:2020-06-05 06:44:52
【问题描述】:

刚刚创建了我的第一个 React-Native 应用程序并使用添加了我的第一个库“react-native-elements”

yarn add react-native-elements

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

Cannot find module 'react-native-elements'

app.tsx

import React from 'react';
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',
  },
});

Package.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 yarnpkg


    【解决方案1】:

    https://react-native-elements.github.io/react-native-elements/docs/troubleshooting.html 你可以试试这个吗?

    yarn - rm -rf node_modules && yarn && yarn add react-native-elements
    npm start -- --reset-cache
    

    【讨论】:

    • 感谢您遇到警告:警告“ > react-native-elements@2.0.2”具有未满足的对等依赖性“react-native-vector-icons@>6.6.0”。跨度>
    • 因为您没有安装 react-native-vector-icon 按照上面的文档并使用 yarn add react-native-vector-icons 和 cd ios pod install 安装
    猜你喜欢
    • 2019-09-06
    • 1970-01-01
    • 1970-01-01
    • 2023-04-06
    • 2023-01-18
    • 2016-10-27
    • 1970-01-01
    • 1970-01-01
    • 2019-04-18
    相关资源
    最近更新 更多