首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用react-native-swiper导入Swiper显示错误

使用react-native-swiper导入Swiper显示错误
EN

Stack Overflow用户
提问于 2018-07-19 14:37:22
回答 1查看 1.3K关注 0票数 0

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

下面是我的依赖项:

代码语言:javascript
运行
复制
"react": 16.3.1,
"react-native": "~0.55.2",
"react-native-swiper": "^1.5.13"

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

我的组件如下:

代码语言:javascript
运行
复制
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 />,它也会显示错误

错误:

代码语言:javascript
运行
复制
Failed to load bundle

检查我的终端错误显示:

代码语言:javascript
运行
复制
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 amainmodule field that could not be resolved

我想不出来。有什么是我怀念的吗?

任何帮助都将不胜感激,提前谢谢。

EN

回答 1

Stack Overflow用户

发布于 2021-04-28 23:01:04

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

替换:

代码语言:javascript
运行
复制
module.exports = Swiper;
module.exports.default = Swiper;

通过

代码语言:javascript
运行
复制
export default Swiper
export {Swiper}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51415892

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档