Tic tac toe minimax problem

Hi, I tried to create my Tic-tac-toe game and did it with very simple AI. Now I try to apply Minimax algorithm in my app using this tutorial https://github.com/beaucarnes/fcc-project-tutorials/blob/master/tictactoe/7/script.js. I change it to join with my app’s logic, but get Uncaught RangeError: Maximum call stack size exceeded all the time. Can I get some help?
Link app: https://codepen.io/UnknownElement/pen/LmxebW