From React-Native app can not connect to Parse server.
Failed to create new object, with error code: XMLHttpRequest failed: {"line":104828,"column":32,"sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false"}
import React from 'react';
import { Parse } from 'parse/react-native'
import { AsyncStorage } from '@react-native-community/async-storage'
Parse.setAsyncStorage(AsyncStorage)
Parse.initialize("APP_ID", "JS_KEY")
Parse.serverURL = 'https://parseapi.back4app.com/'
export default class App extends React.Component {
constructor(props) {
super(props)
}
componentDidMount() {
/**
* Test part 1
*/
var Test = Parse.Object.extend("Test");
var test = new Test();
test.set("name", "test_name");
test.save()
.then((obj) => {
alert('New object created with objectId: ' + obj.id);
}, (error) => {
console.debug('Failed to create new object, with error code: ' + error.message);
});
/**
* Test part 2
*/
let install = new Parse.Installation();
install.set("deviceType", 'navigator.userAgent');
install.save().then((resp) => {
console.log('Created install object', resp);
this.setState({
result: 'New object created with objectId: ' + resp.id
})
}, err => {
console.log('Error creating install object', err);
this.setState({
result: 'Failed to create new object, with error code: ' + err.message
})
})
}
render() {
return null
}
}
Cannot request to server.
Back4App serverFailed to create new object, with error code: XMLHttpRequest failed: {"line":104828,"column":32,"sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false"}
Server
2.8.4 to 3.9.0back4app.back4app and my own parse-server.JS SDK
2.11.0React-Native 0.61.5Run test on iOS simulators and my iPhone
I make sure to run test over VPN.
There are no problem when I work with Parse-Server via Restful Api (Postman and fetch in React Native app) or ReactJS web app. Just React-Native with SDK is error.
Failed to create new object, with error code: XMLHttpRequest failed: {"line":104828,"column":32,"sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false"}
Error creating install object [Error: XMLHttpRequest failed: {"line":104828,"column":32,"sourceURL":"http://localhost:8081/index.bundle?platform=ios&dev=true&minify=false"}]
After some days debug. I think It's seem there are no any connections from app to servers (my server and back4app)
Can you please try by installing from this branch? https://github.com/back4app/Parse-SDK-JS/tree/fixReactNative
Can you please try by installing from this branch? https://github.com/back4app/Parse-SDK-JS/tree/fixReactNative
WOW !!! IT'S WORKS PERFECT !!!
But is the patch you made is ready for production or just testing purpose ?
I'm glad it worked! I think you can use my branch for development purposes but It would be better wait for the next release of JS SDK before going to production.
Most helpful comment
I'm glad it worked! I think you can use my branch for development purposes but It would be better wait for the next release of JS SDK before going to production.