我试着使用这个库https://github.com/leecade/react-native-swiper中的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 amainmodule field that could not be resolved
我想不出来。有什么是我怀念的吗?
任何帮助都将不胜感激,提前谢谢。
发布于 2021-04-28 23:01:04
在node_modules中找到文件夹react-native-swiper并这样做,它对我很有效
替换:
module.exports = Swiper;
module.exports.default = Swiper;通过
export default Swiper
export {Swiper}https://stackoverflow.com/questions/51415892
复制相似问题