0

我尝试使用这个库中的 swiper https://github.com/leecade/react-native-swiper

这是我的依赖项:

"react": 16.3.1,
"react-native": "~0.55.2",
"react-native-swiper": "^1.5.13"

但是当我添加这段代码时import Swiper from 'react-native-swiper';

我的组件像:

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

class Welcome extends Component {
  render() {
    return (
      <View>
        <Text>Welcome</Text>
      </View>
    );
  }
}

export default Welcome;

即使我不使用它也会显示错误<Swiper />

错误:

Failed to load bundle

在此处输入图像描述

检查我的终端错误显示:

error: bundling failed: Error: While trying to resolve module `react-native-swiper` from file `/Users/huaweb/ReactNativeProject/Huaweb/src/components/Welcome.js`, the package `/Users/huaweb/ReactNativeProject/Huaweb/node_modules/react-native-swiper/package.json` was successfully found. However, this package itself specifies a `main` module field that could not be resolved (`/Users/huaweb/ReactNativeProject/Huaweb/node_modules/react-native-swiper/index.js`. Indeed, none of these files exist:

不知道However, this package itself specifies a主要是什么module field that could not be resolved

我想不通。有什么我想念的吗?

任何帮助将不胜感激,在此先感谢。

4

1 回答 1

0

在 node_modules 中找到文件夹 react-native-swiper 并这样做,它对我有用

代替 :

module.exports = Swiper;
module.exports.default = Swiper;

经过

export default Swiper
export {Swiper}
于 2021-04-28T15:01:03.730 回答