Solved

Maximum call stack size exceeded

  • 12 September 2018
  • 4 replies
  • 687 views

Userlevel 3
Badge

I noticed that in my browser console, I am seeing the following error whenever I generate a mixpanel event.

mixpanel-2-latest.min.js:66 Uncaught RangeError: Maximum call stack size exceeded

This appears to be a recent error and I am unsure what is causing it. Has anyone ever come across this error before and is there a known fix?


icon

Best answer by michael 12 September 2018, 02:53

Hi @landon_bartels- welcome to the Mixpanel Community!

We've typically seen the 'maximum call stack size exceeded' error when there are multiple instances of our Mixpanel library snippet being injected and loaded on a webpage. If you take a closer look at the page source of your website can you find two + instances of the Mixpanel library being loaded on your web page? Common places this could be are one in the head tags and one in the body, or in some external JS being included on the page.

If you can consolidate the two sets of tracking code, and leave one snippet of the Mixpanel library in the header of your page, the errors should go away. Is there a reason you call a Mixpanel event more than once?

Please let me know if you have any follow up questions, if my assumption was wrong and there are not multiple snippets being initiated, or if the errors persist even after you've rid of the extra library snippet. Happy to continue to troubleshoot with you until this is resolved.


View original

4 replies

Userlevel 4
Badge +2

Hi @landon_bartels- welcome to the Mixpanel Community!

We've typically seen the 'maximum call stack size exceeded' error when there are multiple instances of our Mixpanel library snippet being injected and loaded on a webpage. If you take a closer look at the page source of your website can you find two + instances of the Mixpanel library being loaded on your web page? Common places this could be are one in the head tags and one in the body, or in some external JS being included on the page.

If you can consolidate the two sets of tracking code, and leave one snippet of the Mixpanel library in the header of your page, the errors should go away. Is there a reason you call a Mixpanel event more than once?

Please let me know if you have any follow up questions, if my assumption was wrong and there are not multiple snippets being initiated, or if the errors persist even after you've rid of the extra library snippet. Happy to continue to troubleshoot with you until this is resolved.


Badge

Hello, I am having the same issue but the difference is that I am launching mixpanel events through Google Tag Manager where I have to launch before every event the library tag so it functions properly as notice in the help notes. How should I implement properly in this case? I suspect that this error I am having is because I am launching repeatedly on the same page.


Thank in advance


Userlevel 4
Badge +2

@adalmagro, In the case of GTM implementations, we recommend placing the Mixpanel snippet on the page directly if possible to ensure it loads properly instead of using GTM to load the Mixpanel library. That will prevent it from loading it multiple times on the same page, to prevent that "Maximum call stack size exceeded" problem, and also ensures it will load before any of your track calls.


This error is almost always means you have a problem with recursion in JavaScript code, as there isn't any other way in JavaScript to consume lots of stack.  Sometimes calling a recursive function over and over again, causes the browser to send you Maximum call stack size exceeded error message as the memory that can be allocated for your use is not unlimited. It's possible to cause infinite recursion in a fully promisified code, too. That can happen if the promises in a chain don't actually perform any asynchronous execution , in which case control never really returns to the event loop, even though the code otherwise appears to be asynchronous. That's when it's useful to wrap your recursive function call into a -

  • setTimeout
  • setImmediate or
  • process.nextTick

Also, you can localize the issue by setting a breakpoint on RangeError type of exception , and then adjust the code appropriately. Moreover, you can managed to find the point that was causing the error by check the error details in the Chrome dev toolbar console , this will give you the functions in the call stack, and guide you towards the recursion that's causing the error.

 

Reply