我正在尝试使用 React Native Expo 来使用 Back4App,但我不断收到与 Parse.initialize 语句相关的 TypeError。如果我注释掉这条语句,应用程序会在模拟器中很好地加载,但是一旦取消注释该语句,就会抛出错误。
“错误 TypeError:尝试在非实例上使用私有字段,js 引擎:hermes”
我的App.js:
import { StatusBar } from 'expo-status-bar';
import { StyleSheet, Text, View, SafeAreaView, Button, TextInput } from 'react-native';
import { useState } from 'react';
import Parse from 'parse/react-native.js';
import AsyncStorage from '@react-native-async-storage/async-storage';
Parse.setAsyncStorage(AsyncStorage);
Parse.serverURL = 'https://parseapi.back4app.com/';
Parse.initialize("xxxxxxxxxx","xxxxxxxxx");
export default function App() {
const [todoTitle, setTodoTitle] = useState("");
return (
<SafeAreaView>
<StatusBar style="auto" />
<View style={styles.container}>
<View style={styles.header}>
<Text style={styles.headerText}>My Todo List</Text>
<Text style={styles.descriptionText}>List of activities I need to accomplish</Text>
</View>
<View style={styles.formContainer}>
<TextInput placeholder="Add a new todo" onChangeText={setTodoTitle} style={styles.input} />
<Button title="Add" />
</View>
</View>
</SafeAreaView>
);
}
const styles = StyleSheet.create({
container: {
backgroundColor: '#fff',
marginTop: StatusBar.height
},
header: {
height: 200,
backgroundColor: "blue",
justifyContent: "center",
alignItems: "center",
padding: 15,
},
headerText: {
color: "white",
fontSize: 30,
marginBottom: 10,
fontWeight: "bold",
},
descriptionText: {
color: "white",
fontSize: 20,
},
formContainer: {
backgroundColor: "lightblue",
padding: 20,
},
formText: {
fontWeight: "bold",
fontSize: 15,
},
input: {
backgroundColor: "white",
padding: 10,
marginBottom: 10,
borderRadius: 5,
borderWidth: 1,
borderColor: "lightblue",
}
});
任何帮助将不胜感激。
我尝试在snack.expo.dev中重做应用程序,但不断收到“模块parse/react-native.js无法解析”的错误。只是想看看我的开发设置是否导致了问题。
我在Expo sdk v50上遇到了同样的错误,我已经通过以下解决方案解决了。
-之前:
var EventEmitter;
try {
EventEmitter = require('react-
native/Libraries/vendor/emitter/EventEmitter');
if (EventEmitter.default) {
EventEmitter = EventEmitter.default;
}
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
} catch (_) {}
module.exports = EventEmitter;
-之后:
module.exports = require('events').EventEmitter;
var EventEmitter;
npm install(或yarn add)事件 这个“事件”模块是针对 Node.js 的,所以没有预装在react-native 中,而是实际运行在react-native 上。
npx 博览会开始-c
我希望这对您和其他世博用户有用。