[SOLVED] App acting strange

For some reason every time I try to run my page I’m getting Parse.initialize error for these 2 functions from this component:

    async componentDidMount() {
      const  Moralis  = require('moralis')
      await Moralis.initialize()
      const params = { search: this.state.searchcontent };
      await Moralis.Cloud.run("searchResults", params).then((result) =>
       this.setState({searchResults: [JSON.stringify(result)] })
      );
    }
    async searchList() {
      const  Moralis  = require('moralis')
      await Moralis.initialize()
        const user = await Moralis.User.current()
        const List = Moralis.Object.extend("Friends");
        const addFriend = new List();
        let keys= Object.keys(this.state.searchResults)
        return keys.map(key =>
          <div>
              <p>{this.state.searchResults[key]}</p>
              <Button onClick={addFriend.save({username: 'blueflame', name: 'Wes Bond', user: user.get('username')})}>Add Friend</Button>
              <Button>Message</Button>
          </div>
        )
      }

even though I’m connected to internet and my app info is correct (I updated npm and my server as well):

ReactDOM.render(
    <MoralisProvider appId='76XaqF58HRAB1mPXlo77qnaQ3yZmCpNKmTkSDqE6' serverUrl='https://oorfqpisq8bs.grandmoralis.com:2053/server'>
        <App /> 
     </MoralisProvider> 
     , document.getElementById('root'));

Also I’m not able to logout either even though all of this was working not too long ago… my Queries arent returning anything either

what would you expect to happen when you call Moralis.initialize() ?
what you want it to do there?

please disregard… I only put it there hoping it would solve the Parse.initialize error, it has since been deleted

if you use Moralis.start after that line it would work fine?

Says it is not a function

Unhandled Rejection (TypeError): Moralis.start is not a function

what version of Moralis are you using?
you can find the version with console.log(Moralis.CoreManager.get("VERSION"))

you could also try to move this line outside those 2 functions

Version: js0.0.54

I also moved the line outside of the 2 functions… same error

latest version or Moralis SDK is 0.0.110, you could update to a newer version of Moralis SDK

Okay I manually changed that in package.json? Same error

what is the error that you see?

Sorry youre, right that got rid of the errors, however instead of loading the search modal all of my components dissapear…

    openSearch() {
      this.setState({ showsearch: true });
    } 

    async componentDidMount() {
      const params = { search: this.state.searchcontent };
      await Moralis.Cloud.run("searchResults", params).then((result) =>
       this.setState({searchResults: [JSON.stringify(result)] })
      )
    } 
return(
<Button variant='info' type='submit' onClick={() => {this.openSearch(); this.componentDidMount();}} className='navsearch'><i class="fa fa-search" aria-hidden="true"></i></Button>
)

however if I comment out the compenentDidMount() function the modal loads just fine (although with no data obviously)

You can close this… I basically converted the class component to function and used react-moralis instead

1 Like