Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve Maximum call stack size exceeded Error in nuxt.js

I'm trying to get data from firebase using axios. I'm using vuex store to handle all my data .

I've this two actions to get the data and store it :

nuxtServerInit(vuexContext, context) {
        return axios
          .get("https://nuxt-blog.firebaseio.com/posts.json")
          .then(res => {
            const postsArray = [];
            for (const key in res.data) {
              postsArray.push({ ...res.data[key], id: key });
            }
            vuexContext.commit("setPosts", postsArray);
          })
          .catch(e => context.error(e));
      },
      setPosts(vuexContext, posts) {
        vuexContext.commit("setPosts", posts);
      }

I don't know what is wrong with this code but it gives me this errors :

Maximum call stack size exceeded

errors on terminal

like image 265
Ayman Tarig Avatar asked Apr 19 '19 08:04

Ayman Tarig


People also ask

How do I fix maximum call stack size exceeded?

The call stack is limited in size, and when it's exceeded, the RangeError is thrown. This can happen when a deeply nested function is called, or when a lot of new variables are created. The most common way to fix this error is to reduce the number of function calls, or to limit the number of variables that are created.

What is the size of call stack?

Without any local variables, each function call takes up 48 bytes during the execution, and you are limited to less than 1MB for all local function frames. Each boolean and number variable takes 8 bytes of memory.

Is NUXT JS frontend or backend?

js is a frontend framework built upon Vue. js that offers great development features such as server side rendering, automatically generated routes, improved meta tags managing and SEO improvement.


1 Answers

You should put only POJO objects into vuex. Most likely you are putting some heavily nested object into it. E.g. res.data contains some non Pojo object that u are putting into vuex

like image 127
Aldarund Avatar answered Nov 15 '22 05:11

Aldarund