[SOLVED] How to deal with: RangeError:Maximum call stack size exceeded

defineNewMonster = async (name,health,strength) =>{

    const MonsterCreature = Moralis.Object.extend("Monster");

    const monster = new MonsterCreature();

    monster.set('health',health);

    monster.set('strength',strength);

    monster.set('name',name);

    const fileUploadControl = document.getElementById("profilePhotoFileUpload");

    if(fileUploadControl.files.length>0){

        const file = fileUploadControl.files[0];

        const name = "profile_picture.png";

        const moralisFile = new Moralis.File(name,file);

        await moralisFile.save();       

        console.log('profile_picture url.',moralisFile.url());

        monster.set('profile_picture',moralisFile);        

    }

    console.log('do save');

    monster.save().then((obj) =>{

      console.log('New object created with objectId: ' + obj.id);

    },(error) =>{

      console.log('Failed to create new object, with error code: ' + error.message);

    });

}

moralis.js:27436 Uncaught (in promise) RangeError: Maximum call stack size exceeded

at traverse (moralis.js:27436)

at traverse (moralis.js:27492)

Hey @milk3688

Please post full code. Probably you have infinite function calling because of rerendering the component… Wrap it to the useEffect hook

I later changed the way the code was called to get around this problem

So does it work correctly now?

Yeah, I rewrote the code and it works

Please how did you solve this problem, I am having similar problem

//store on moralis
    const Proposals = Moralis.Object.extend("Proposals");
    const proposals = new Proposals();

    proposals.set("proposalId", id);
    proposals.set("description", description);
    proposals.set("title", title);
    proposals.set("proposer", user);
    proposals.set("govAddress", props.contract.get("govAddress"));

    proposals.save().then(
      (proposals) => {
        setLoadingStart(false);
        setTask("success");

        props.setSection("proposals");
        props.hide(false);
      },
      (error) => {
        setLoadingStart(false);
        Swal.fire({
          title: "Error!",
          text:
            "Failed to create new object, with error code: " + error.message,
          icon: "error",
          confirmButtonText: "Ok",
          confirmButtonColor: "#2C6CF4",
        });
      }
    );

you have to identify first what line gives that error, usually somewhere is sent as parameter a variable instead of a value

1 Like