Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

React Native ScrollView TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach')

I'm building React Native app with Expo. It works fine on my Android device via Expo application. But I have the error after I've built apk via exp build:android command.

TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach')                                                  
This error is located at:
  in ScrollView
  in RCTView
  in r
  in Connect(r)
  in n
  in t
  in r
  in RCTView
  in RCTView
  in t

Problem is inside ScrollView. It is gone if I remove ScrollView. Here is my code snippet.

class Main extends Component {
state = {
    refreshing: false
};

renderCurrencies() {
    if (!Object.values(this.props.currencies).length) {
        return <View />;
    }

    return Object.values(this.props.currencies).map(item => {
        return (
            <CurrencyRow
                key={item.code}
                code={item.code}
                title={item.title}
            />
        );
    });
}

onRefresh = () => {
    Object.values(this.props.currencies).map(item => {
        this.props.sellBuyFetch(item.code);
    });
};

render() {
    return (
        <View style={styles.container}>
            <ScrollView
                refreshControl={
                    <RefreshControl
                        refreshing={this.state.refreshing}
                        onRefresh={this.onRefresh}
                    />
                }
            >
                {this.renderCurrencies()}
            </ScrollView>
        </View>
    );
}
}

const styles = StyleSheet.create({
container: {
    flex: 1,
    marginTop: 40,
},
});
like image 617
Dima Portenko Avatar asked Dec 25 '17 22:12

Dima Portenko


2 Answers

This bug is caused by uglify-es 3.3.X which is used when building a release version.

Add this block to your package.json:

"resolutions": { "uglify-es": "3.2.2" }

I tried both publishing on Expo and building a standalone app and it's working like a charm now.

like image 153
Moe Avatar answered Nov 01 '22 14:11

Moe


Had same issue. Way to resolve this:

change

this._subscribableSubscriptions.forEach(

to

this._subscribableSubscriptions && this._subscribableSubscriptions.forEach(

in that file:

YOUR_PROJECT/node_modules/react-native/Libraries/Components/Subscribable.js 
like image 4
KyKaPeTuK Avatar answered Nov 01 '22 16:11

KyKaPeTuK