【问题标题】:react-native-community/CheckBox can't resolve modulereact-native-community/CheckBox 无法解析模块
【发布时间】:2021-03-11 16:26:56
【问题描述】:

这看起来是一个简单的问题,答案很简单,即 npm install @react-native-community/checkbox 但它不起作用。我有一个错误说该包依赖于 react-native-windows,所以我也下载了这个包,导致无法解决我的问题。

我真的不明白为什么会这样......

这是我的 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": {
    "@react-native-community/checkbox": "^0.5.6",
    "expo": "~39.0.2",
    "expo-status-bar": "~1.0.2",
    "moviedb-promise": "^3.1.2",
    "react": "16.13.1",
    "react-dom": "16.13.1",
    "react-image": "^4.0.3",
    "react-native": "https://github.com/expo/react-native/archive/sdk-39.0.2.tar.gz",
    "react-native-web": "~0.13.12",
    "react-native-windows": "^1.0.0",
    "react-tinder-card": "^1.3.1"
  },
  "devDependencies": {
    "@babel/core": "~7.9.0"
  },
  "private": true
}

编辑

这是我的代码:

import React from 'react'
import { View, Text } from 'react-native';
import CheckBoxSetting from './CheckBoxSetting';
import PressableSetting from './PressableSetting'
import SwitchSetting from './SwitchSetting';

function SettingItemFactory () {
    this.createSettingItem  = function (name, type, initState) {
        let settingItem = <Text/>;
        switch(type){
            case 'pressable':
                settingItem = <PressableSetting title={name}/>;
                break;
            case 'switch':
                settingItem = <SwitchSetting name={name} state={initState}/>
                break;
            case 'check':
                settingItem = <CheckBoxSetting name={name} state={initState}/>
                break;
            default:
                settingItem = <PressableSetting title={name} />;
        }
        return settingItem;
    }
}

export default SettingItemFactory;

import React from 'react'
import {View, Text, ImagePropTypes} from 'react-native'
import CheckBox from '@react-native-community/checkbox'


const CheckBoxSetting = (props) => {
    return (
        <View>
            <Text>
                {props.name}
            </Text>
        </View>
    )
}

export default CheckBoxSetting;

【问题讨论】:

  • 您可以尝试删除node_modules并运行npm install重新安装所有模块。有时它会有所帮助
  • 我确实试过了,但并没有解决问题,但谢谢:)
  • 确切的错误信息是什么?什么时候收到?
  • 我猜这个库不支持 expo。
  • @LeGiNaCl 官方文档说你需要在windows上手动链接。你查到了吗?

标签: reactjs react-native expo node-modules


【解决方案1】:

Tushar Khatiwada 在原帖的 cmets 中给出了答案: 截至目前,expo 不支持该库。谢谢图沙尔!

【讨论】:

  • 我在 react native cli 项目中也看到了同样的错误
【解决方案2】:

如果您在 react-native 项目中使用 expo,expo 提供了一个可以利用的 Checkbox 组件,它似乎使用与 react-native CheckBox 组件相同的 API。 :)

https://docs.expo.io/versions/latest/sdk/checkbox/

【讨论】:

    【解决方案3】:

    世博会不支持。 在 react-native CLI 中,确保链接已完成并进行 pod install。

    【讨论】:

      猜你喜欢
      • 2020-10-27
      • 2017-10-11
      • 2016-03-23
      • 1970-01-01
      • 2018-11-18
      • 1970-01-01
      • 2020-04-15
      • 2020-03-02
      • 2016-12-27
      相关资源
      最近更新 更多