React-native-swiper: Cannot assign to read only property 'exports' of object - error

Created on 30 Nov 2019  路  6Comments  路  Source: leecade/react-native-swiper

Which OS ?

Windows

Version

Which versions are you using:

  • react-native-swiper v?1.5.14
  • react-native v0.?.?0.59.8

Expected behaviour

Basic swipe functionaly code works

Actual behaviour

Cannot assign to read only property 'exports' of object - error
AvatarSelectionScreen_BasicSwipe.txt
Error

How to reproduce it>

To help us, please fork this component, modify one example in examples folder to reproduce your issue and include link here.
-

Steps to reproduce

  1. Create a react-native project.
  2. Copy the below code from the github README
    import React, { Component } from 'react'
    import { AppRegistry, StyleSheet, Text, View } from 'react-native'

import Swiper from 'react-native-swiper'

const styles = StyleSheet.create({
wrapper: {},
slide1: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#9DD6EB'
},
slide2: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#97CAE5'
},
slide3: {
flex: 1,
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#92BBD9'
},
text: {
color: '#fff',
fontSize: 30,
fontWeight: 'bold'
}
})

export default class SwiperComponent extends Component {
render() {
return (







)
}
}

AppRegistry.registerComponent('myproject', () => SwiperComponent)
3.Modified as attached in AvatarSelectionScreen_BasicSwipte.txt

  1. Yarn add react-native-swiper
  2. Yarn start

Most helpful comment

The solution that worked for me is import Swiper from 'react-native-swiper/src'.

The code for index.js simply exports the Swiper in src.

import Swiper from './src/'
/**
 * Resolve ES6 and CommonJS compatibility issues
 * 1. CommonJS code
 *    const Swiper = require('react-native-swiper');
 * 2. ES6 code
 *    import Swiper from 'react-native-swiper';
 */
module.exports = Swiper;
module.exports.default = Swiper;

All 6 comments

RESOLVED, after spending hours !!!
Changed: module.exports = Swiper line from react-native-swiper/index.js to export default Swiper;

RESOLVED, after spending hours !!!
Changed: module.exports = Swiper line from react-native-swiper/index.js to export default Swiper;

Thanks! Works for me.

Have the same problem, it would be nice to be es6 syntax by default or having something like

if( module ) { module.export.. }
else { export default .. }

Thanks for the awesome work ;)

The solution that worked for me is import Swiper from 'react-native-swiper/src'.

The code for index.js simply exports the Swiper in src.

import Swiper from './src/'
/**
 * Resolve ES6 and CommonJS compatibility issues
 * 1. CommonJS code
 *    const Swiper = require('react-native-swiper');
 * 2. ES6 code
 *    import Swiper from 'react-native-swiper';
 */
module.exports = Swiper;
module.exports.default = Swiper;

RESOLVED, after spending hours !!!
Changed: module.exports = Swiper line from react-native-swiper/index.js to export default Swiper;

Could not understand, can you please explain it again ?

The solution that worked for me is import Swiper from 'react-native-swiper/src'.

The code for index.js simply exports the Swiper in src.

import Swiper from './src/'
/**
 * Resolve ES6 and CommonJS compatibility issues
 * 1. CommonJS code
 *    const Swiper = require('react-native-swiper');
 * 2. ES6 code
 *    import Swiper from 'react-native-swiper';
 */
module.exports = Swiper;
module.exports.default = Swiper;

This works for me, Thank You derdoses.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

commit-master picture commit-master  路  3Comments

ghost picture ghost  路  3Comments

Liqiankun picture Liqiankun  路  3Comments

JonasOmdal picture JonasOmdal  路  3Comments

nicolabortignon picture nicolabortignon  路  3Comments