leecade / react-native-swiper

The best Swiper component for React Native.
MIT License
10.42k stars 2.34k forks source link

Cannot assign to read only property 'exports' of object - error #1117

Open Ruta-Radiya opened 4 years ago

Ruta-Radiya commented 4 years ago

Which OS ?

Windows

Version

Which versions are you using:

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 (

Hello Swiper Beautiful And simple
)

} }

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

  1. Yarn add react-native-swiper
  2. Yarn start
Ruta-Radiya commented 4 years ago

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

evie9z commented 4 years ago

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

Thanks! Works for me.

Makio64 commented 4 years ago

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 ;)

daredoes commented 4 years ago

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;
SKNAUSAD97 commented 3 years ago

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 ?

SKNAUSAD97 commented 3 years ago

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.