next.js: Maximum call stack size exceeded

Link to the code that reproduces this issue

https://github.com/Deeds67/nextjs-max-call-stack-size-exceeded

To Reproduce

  1. Add dependency "@material-tailwind/react": "^2.1.0",
  2. Create a NavbarDefault component as listed here: https://www.material-tailwind.com/docs/react/navbar#navbar
  3. Render this component on a page
  4. Run npm run build

Current vs. Expected behavior

Current behavior:

Build fails with the following error: RangeError: Maximum call stack size exceeded

Expected behavior: Build should successfully pass.

Here’s the full error output:

✗ npm run build

> max-call-stack-error@0.1.0 build
> next build

 ✓ Creating an optimized production build    
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
   Generating static pages (0/5)  [    ]RangeError: Maximum call stack size exceeded
    at P (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:231722)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:227295)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228496
    at Array.forEach (<anonymous>)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228469
    at Array.forEach (<anonymous>)
    at a (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228289)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228553
    at Array.forEach (<anonymous>)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228246)

Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
RangeError: Maximum call stack size exceeded
    at P (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:231722)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:227295)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228496
    at Array.forEach (<anonymous>)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228469
    at Array.forEach (<anonymous>)
    at a (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228289)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228553
    at Array.forEach (<anonymous>)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228246)
RangeError: Maximum call stack size exceeded
    at P (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:231722)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:227295)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228496
    at Array.forEach (<anonymous>)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228469
    at Array.forEach (<anonymous>)
    at a (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228289)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228553
    at Array.forEach (<anonymous>)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228246)

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
RangeError: Maximum call stack size exceeded
    at P (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:231722)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:227295)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228496
    at Array.forEach (<anonymous>)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228469
    at Array.forEach (<anonymous>)
    at a (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228289)
    at /home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228553
    at Array.forEach (<anonymous>)
    at l (/home/pierre/dev/ts/max-call-stack-error/.next/server/chunks/241.js:5:228246)
 ✓ Generating static pages (5/5) 

> Export encountered errors on following paths:
	/_not-found
	/page: /

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #202309191142~1695998943~22.04~070916d SMP PREEMPT_DYNAMIC Fri S
Binaries:
  Node: 20.3.1
  npm: 9.6.7
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 13.5.5-canary.4
  eslint-config-next: 13.5.4
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Additional context

App works when running npm run dev, but not when building a production ready app using npm run build

WEB-1744

About this issue

  • Original URL
  • State: closed
  • Created 9 months ago
  • Reactions: 2
  • Comments: 16 (7 by maintainers)

Commits related to this issue

Most upvoted comments

I managed to work around the issue by reverting to an older version: "next": "13.5.3". Bug appears in 13.5.4 and later.

@kelihansen If so, please file another issue. It’s a different one.

I’ve faced same issue with Nextjs 13.5.4. I downgraded to 13.4.7 and built successfully.

  • 13.4.19 is also succeeded.

Hello, I’ve faced same issue with Nextjs 13.5.4