我正在使用Expo构建React Native应用程序 . 它通过Expo应用程序在我的Android设备上运行良好 . 但是我通过exp build:android命令构建了apk后出现错误 .
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
问题出在ScrollView中 . 如果我删除ScrollView,它就消失了 . 这是我的代码片段 .
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,
},
});
5 回答
我认为你的代码使用FlatList会更简单,但是你的问题可能在这个方法中:renderCurrencies()
尝试将其更改为:
renderCurrencies =()=> {
也许是找不到道具 . 你在日志中看到任何其他问题吗?如果这没有帮助,请调试问题并查找if(this)中是否包含该方法 .
注意:我还没有参加过世博会 .
此错误是由构建发布版本时使用的
uglify-es 3.3.X
引起的 .将此块添加到package.json:
"resolutions": { "uglify-es": "3.2.2" }
我尝试在Expo上发布并构建一个独立的应用程序,它现在就像一个魅力 .
可能是React Native 0.5.1中的错误 .
我通过评估第33行上的变量this._subscribableSubscriptions来修复它本地文件项目/ node_modules / react-native / Libraries / Components / Subscribable.js
改变这个:
对此:
https://github.com/facebook/react-native/issues/17348
有同样的问题 . 解决这个问题的方法:
更改
至
在该文件中:
谢谢,@kykapetuk和@chillypenguin . 看起来像这个React Native bug https://github.com/facebook/react-native/issues/17348 . 如果是世博会,我们可以使用世博会 . 也许,这里可能的解决方案是使用另一个版本的react-native库 .