'RangeError: Maximum call stack size exceeded at Array.map (<anonymous>) when trying to deploy to heroku

I am trying to deploy an mern stack app to heroku when I got this error in heroku cli.

RangeError: /tmp/build_c861a30c/frontend/node_modules/@reduxjs/toolkit/dist/redux-toolkit.esm.js: Maximum call stack size exceeded
           at Array.map (<anonymous>)
           at Array.map (<anonymous>)
           at Array.map (<anonymous>)
       
       
-----> Build failed

The app itself works fine on localhost so I don't really understand where this error is coming from. The app code is located here: https://github.com/gbopola/mern-learn-tut-2022



Solution 1:[1]

Tried to run in my computer and it is giving me the following error: Failed to compile.

RangeError: /home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@reduxjs/toolkit/dist/redux-toolkit.esm.js: Maximum call stack size exceeded
    at Array.map (<anonymous>)
    at Array.map (<anonymous>)
    at Array.map (<anonymous>)
asset static/js/bundle.js 3.45 MiB [emitted] (name: main) 1 related asset
asset index.html 1.68 KiB [emitted]
asset asset-manifest.json 190 bytes [emitted]
runtime modules 28.1 KiB 13 modules
modules by path ./node_modules/ 3.03 MiB 177 modules
modules by path ./src/ 62.7 KiB
  modules by path ./src/features/ 10.7 KiB 4 modules
  modules by path ./src/components/*.jsx 11.7 KiB 4 modules
  modules by path ./src/*.js 11.4 KiB
    ./src/index.js 2.1 KiB [built] [code generated]
    + 2 modules
  modules by path ./src/pages/*.jsx 16.7 KiB
    ./src/pages/Dashboard.jsx 4.04 KiB [built] [code generated]
    + 2 modules
  modules by path ./src/*.css 11 KiB
    ./src/index.css 2.72 KiB [built] [code generated]
    ./node_modules/css-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[1]!./node_modules/postcss-loader/dist/cjs.js??ruleSet[1].rules[1].oneOf[5].use[2]!./node_modules/source-map-loader/dist/cjs.js!./src/index.css 8.29 KiB [built] [code generated]
  ./src/app/store.js 1.26 KiB [built] [code generated]

WARNING in src/components/Header.jsx
  Line 1:9:  'FaSignInAlt' is defined but never used  no-unused-vars

src/pages/Login.jsx
  Line 6:9:  'FaUser' is defined but never used  no-unused-vars

ERROR in ./node_modules/@reduxjs/toolkit/dist/redux-toolkit.esm.js
Module build failed (from ./node_modules/babel-loader/lib/index.js):
RangeError: /home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@reduxjs/toolkit/dist/redux-toolkit.esm.js: Maximum call stack size exceeded
    at Object.decode (/home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@jridgewell/sourcemap-codec/dist/sourcemap-codec.umd.js:36:20)
    at new TraceMap (/home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@jridgewell/trace-mapping/dist/trace-mapping.umd.js:187:48)
    at /home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@ampproject/remapping/dist/remapping.umd.js:230:26
    at Array.map (<anonymous>)
    at build (/home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@ampproject/remapping/dist/remapping.umd.js:206:42)
    at /home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@ampproject/remapping/dist/remapping.umd.js:230:20
    at Array.map (<anonymous>)
    at build (/home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@ampproject/remapping/dist/remapping.umd.js:206:42)
    at /home/hafizur/projects/stackoverflow/mern-learn-tut-2022/frontend/node_modules/@ampproject/remapping/dist/remapping.umd.js:230:20
    at Array.map (<anonymous>)
 @ ./src/app/store.js 3:0-50 6:21-35
 @ ./src/index.js 8:0-36 14:11-16

webpack 5.69.0 compiled with 1 error and 1 warning in 30571 ms

from what u are saying, it runs perfectly fine on ur local computer, this probably means u are using an older version of npm and/or nodejs with older packages and stuff, and the Heroku is probably trying to build with the latest packages, u might just want to update ur npm & nodejs and reinstall the node modules, this will probably cause u to be able to recreate this error in ur local machine and therefore it would be easier to debug, note: I'm not sure about any of these

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hafizur046