Parse-sdk-js: Failed to create new object, with error code: XMLHttpRequest failed:...

Created on 22 Feb 2020  路  3Comments  路  Source: parse-community/Parse-SDK-JS

Issue Description

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"}

Steps to reproduce

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
  }
}

Expected Results

Cannot request to server.

  • Back4App server
  • and my own server on Docker publish using ngrok with SSL.
    Same error in two cases above.

Actual Outcome

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"}

Environment Setup

  • Server

    • parse-server version: Test from 2.8.4 to 3.9.0
    • Operating System: Don't know, I am using back4app.
    • Hardware: Don't know, I am using back4app.
    • Localhost or remote server? : back4app and my own parse-server.
  • JS SDK

    • JS SDK version: 2.11.0
    • Application? (Browser, Node, React-Native, etc): React-Native 0.61.5
  • Run test on iOS simulators and my iPhone

  • Run test on Android emulator
  • I make sure APP_ID, JS_KEY is correct.
  • I make sure turn off firewall on my macOS.
  • 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.

Logs/Trace

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)

pr-submitted

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.

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bezi picture bezi  路  4Comments

futureinapps picture futureinapps  路  3Comments

Gyran picture Gyran  路  5Comments

lamualfa picture lamualfa  路  5Comments

dylankbuckley picture dylankbuckley  路  4Comments