React Native ScrollView TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach')
React Native ScrollView TypeError: undefined is not an object (evaluating 'this._subscribableSubscriptions.forEach')
我正在使用 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,
},
});
我认为您的代码使用 FlatList 会简单得多,但是您的问题可能出在这个方法中:renderCurrencies()
尝试将其更改为:
renderCurrencies = () => {
可能是没找到道具。您在日志中看到任何其他问题吗?如果这没有帮助,请调试问题并查找 (this) 中是否包含该方法。
注意:我还没有与 Expo 合作过。
有同样的问题。
解决方法:
改变
this._subscribableSubscriptions.forEach(
到
this._subscribableSubscriptions && this._subscribableSubscriptions.forEach(
在该文件中:
YOUR_PROJECT/node_modules/react-native/Libraries/Components/Subscribable.js
谢谢@kykapetuk 和@chillypenguin。看起来像这个 React Native 错误 https://github.com/facebook/react-native/issues/17348。对于 Expo,我们无法使用@kykapetuk 解决方法,因为 APK 是在 Expo 服务器上构建的。我目前的解决方法 - 不要使用 Expo。可能,这里可能的解决方案是使用另一个版本的 react-native 库。
此错误是由构建发布版本时使用的 uglify-es 3.3.X
引起的。
将此块添加到您的 package.json:
"resolutions": {
"uglify-es": "3.2.2"
}
我尝试在 Expo 上发布和构建一个独立的应用程序,现在它运行得很好。
可能是 React Native 0.5.1 中的错误。
我通过在 React Native 文件 project/node_modules/react-native/Libraries/Components/Subscribable.jsproject/node_modules/react-native/Libraries/Components/Subscribable.js
的第 33 行评估变量 this._subscribableSubscriptions 来修复它
改变这个:
this._subscribableSubscriptions.forEach(
为此:
this._subscribableSubscriptions && this._subscribableSubscriptions.forEach(
我正在使用 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,
},
});
我认为您的代码使用 FlatList 会简单得多,但是您的问题可能出在这个方法中:renderCurrencies()
尝试将其更改为:
renderCurrencies = () => {
可能是没找到道具。您在日志中看到任何其他问题吗?如果这没有帮助,请调试问题并查找 (this) 中是否包含该方法。
注意:我还没有与 Expo 合作过。
有同样的问题。 解决方法:
改变
this._subscribableSubscriptions.forEach(
到
this._subscribableSubscriptions && this._subscribableSubscriptions.forEach(
在该文件中:
YOUR_PROJECT/node_modules/react-native/Libraries/Components/Subscribable.js
谢谢@kykapetuk 和@chillypenguin。看起来像这个 React Native 错误 https://github.com/facebook/react-native/issues/17348。对于 Expo,我们无法使用@kykapetuk 解决方法,因为 APK 是在 Expo 服务器上构建的。我目前的解决方法 - 不要使用 Expo。可能,这里可能的解决方案是使用另一个版本的 react-native 库。
此错误是由构建发布版本时使用的 uglify-es 3.3.X
引起的。
将此块添加到您的 package.json:
"resolutions": {
"uglify-es": "3.2.2"
}
我尝试在 Expo 上发布和构建一个独立的应用程序,现在它运行得很好。
可能是 React Native 0.5.1 中的错误。
我通过在 React Native 文件 project/node_modules/react-native/Libraries/Components/Subscribable.jsproject/node_modules/react-native/Libraries/Components/Subscribable.js
的第 33 行评估变量 this._subscribableSubscriptions 来修复它改变这个:
this._subscribableSubscriptions.forEach(
为此:
this._subscribableSubscriptions && this._subscribableSubscriptions.forEach(