Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RangeError: Maximum call stack size exceeded. #3944

Closed
vgseven opened this issue Jan 13, 2024 · 10 comments
Closed

RangeError: Maximum call stack size exceeded. #3944

vgseven opened this issue Jan 13, 2024 · 10 comments
Labels

Comments

@vgseven
Copy link

vgseven commented Jan 13, 2024

pnpm run build - executed successfully locally, but on vercel build execution failed with these weird error: RangeError: Maximum call stack size exceeded

build-failed

Error counter by sharp lib next use for Image Processing to serve images, By reducing the version of sharp 0.33.2 to 0.33.1 resolves the error and vercel build executed successfully.

@vgseven vgseven added the triage label Jan 13, 2024
@lovell lovell added question and removed triage labels Jan 13, 2024
@lovell
Copy link
Owner

lovell commented Jan 13, 2024

This looks like an existing problem with Next.js and its file tracing feature.

https://github.com/search?q=repo%3Avercel%2Fnext.js+%22Maximum+call+stack+size+exceeded%22&type=issues&s=created&o=desc

My best guess would be that there's some recursive behaviour in its use of micromatch and that many possible dependency changes can tip it over the call stack limit.

What did Vercel support say when you asked them?

@pkerschbaum
Copy link

FYI I have the same problem. Locally the Next.js build works, but on Vercel.com not.

I tried some sharp versions:

  • with 0.32.6, 0.33.0, 0.33.1 the Vercel.com Next.js builds work
  • with 0.33.2 the Vercel.com Next.js build throws this error:

So IMO the Vercel.com Next.js build throws because of some change between 0.33.1 and 0.33.2: v0.33.1...v0.33.2

(Note that I do not say this must be fixed in sharp; I just want to provide information).

Vercel.com output:

[16:37:42.770] Running build in Washington, D.C., USA (East) – iad1
[16:37:42.895] Cloning github.com/pkerschbaum/dorfspiele-homepage (Branch: main, Commit: 9578722)
[16:37:44.608] Cloning completed: 1.714s
[16:37:51.737] Restored build cache
[16:37:51.827] Running "vercel build"
[16:37:53.419] Vercel CLI 33.1.0
[16:37:53.568] > Detected Turbo. Adjusting default settings...
[16:37:53.782] Detected ENABLE_EXPERIMENTAL_COREPACK=1 and "pnpm@8.9.2" in package.json
[16:37:53.980] Running "install" command: `pnpm install --frozen-lockfile`...
[16:37:54.610] Scope: all 6 workspace projects
[16:37:54.912] ..                                       | Progress: resolved 1, reused 0, downloaded 0, added 0
[16:37:54.974] ..                                       |   +5   -5 +-
[16:37:55.672] ..                                       | Progress: resolved 5, reused 0, downloaded 5, added 5, done
[16:37:56.340] .../sharp@0.33.2/node_modules/sharp install$ node install/check
[16:37:56.935] .../sharp@0.33.2/node_modules/sharp install: Done
[16:37:57.709] 
[16:37:57.709] dependencies:
[16:37:57.710] - sharp 0.33.1
[16:37:57.710] + sharp 0.33.2
[16:37:57.710] 
[16:37:57.733] .. prepare$ node --eval "process.exit(process.env.CI === 'true' ? 0 : -1)" || (husky install && pnpm exec add-all-tsconfigs-as-project-references --monorepo-path=.)
[16:37:58.050] .. prepare: husky - Git hooks installed
[16:37:59.193] .. prepare: $ pnpm exec prettier --write /vercel/path0/tsconfig.json
[16:38:00.093] .. prepare: tsconfig.json 57ms
[16:38:00.129] .. prepare: Done
[16:38:00.130] Done in 6s
[16:38:00.153] Detected Next.js version: 14.0.4
[16:38:00.154] Running "cd ../ && pnpm run build && cd ./web && pnpm run build:next"
[16:38:00.580] 
[16:38:00.580] > dorfspiele-homepage@ build /vercel/path0
[16:38:00.581] > superturbo build
[16:38:00.581] 
[16:38:00.717] • Packages in scope: @dorfspiele-homepage/config-eslint, @dorfspiele-homepage/config-stylelint, @dorfspiele-homepage/config-typescript, @dorfspiele-homepage/superturbo, @dorfspiele-homepage/web
[16:38:00.717] • Running build in 5 packages
[16:38:00.717] • Remote caching enabled
[16:38:00.905] @dorfspiele-homepage/superturbo:build: cache hit, replaying logs 0ef8487f7df6104c
[16:38:00.907] @dorfspiele-homepage/superturbo:build: 
[16:38:00.907] @dorfspiele-homepage/superturbo:build: > @dorfspiele-homepage/superturbo@ build /home/pkerschbaum/workspace/dorfspiele-homepage/platform/superturbo
[16:38:00.907] @dorfspiele-homepage/superturbo:build: > pnpm run internal:build:compile
[16:38:00.907] @dorfspiele-homepage/superturbo:build: 
[16:38:00.907] @dorfspiele-homepage/superturbo:build: 
[16:38:00.907] @dorfspiele-homepage/superturbo:build: > @dorfspiele-homepage/superturbo@ internal:build:compile /home/pkerschbaum/workspace/dorfspiele-homepage/platform/superturbo
[16:38:00.908] @dorfspiele-homepage/superturbo:build: > tsc -p ./tsconfig.build.json
[16:38:00.908] @dorfspiele-homepage/superturbo:build: 
[16:38:00.944] @dorfspiele-homepage/web:build: cache hit, replaying logs b9c95a5b20d50c54
[16:38:00.944] @dorfspiele-homepage/web:build: 
[16:38:00.945] @dorfspiele-homepage/web:build: > @dorfspiele-homepage/web@1.0.0 build /home/pkerschbaum/workspace/dorfspiele-homepage/web
[16:38:00.945] @dorfspiele-homepage/web:build: > pnpm run internal:compile
[16:38:00.945] @dorfspiele-homepage/web:build: 
[16:38:00.945] @dorfspiele-homepage/web:build: 
[16:38:00.945] @dorfspiele-homepage/web:build: > @dorfspiele-homepage/web@1.0.0 internal:compile /home/pkerschbaum/workspace/dorfspiele-homepage/web
[16:38:00.945] @dorfspiele-homepage/web:build: > tsc -p ./tsconfig.project.json
[16:38:00.945] @dorfspiele-homepage/web:build: 
[16:38:00.946] 
[16:38:00.946]   Tasks:    2 successful, 2 total
[16:38:00.946]  Cached:    2 cached, 2 total
[16:38:00.946]    Time:    253ms >>> FULL TURBO
[16:38:00.946] Summary:    /vercel/path0/.turbo/runs/2auEtjkj5vtsVBxNu9bjrqURhCB.json
[16:38:00.947] 
[16:38:01.501] 
[16:38:01.501] > @dorfspiele-homepage/web@1.0.0 build:next /vercel/path0/web
[16:38:01.501] > pnpm run nuke:artifacts && pnpm run internal:compile && pnpm run internal:build:next && pnpm run internal:build:sitemap
[16:38:01.501] 
[16:38:01.955] 
[16:38:01.956] > @dorfspiele-homepage/web@1.0.0 nuke:artifacts /vercel/path0/web
[16:38:01.957] > del-cli --dot=true dist dist-tsc *.tsbuildinfo
[16:38:01.957] 
[16:38:02.617] 
[16:38:02.617] > @dorfspiele-homepage/web@1.0.0 internal:compile /vercel/path0/web
[16:38:02.618] > tsc -p ./tsconfig.project.json
[16:38:02.618] 
[16:38:07.122] 
[16:38:07.123] > @dorfspiele-homepage/web@1.0.0 internal:build:next /vercel/path0/web
[16:38:07.123] > next build
[16:38:07.124] 
[16:38:07.705] Attention: Next.js now collects completely anonymous telemetry regarding usage.
[16:38:07.706] This information is used to shape Next.js' roadmap and prioritize features.
[16:38:07.706] You can learn more, including how to opt-out if you'd not like to participate in this anonymous program, by visiting the following URL:
[16:38:07.706] https://nextjs.org/telemetry
[16:38:07.706] 
[16:38:07.799]    ▲ Next.js 14.0.4
[16:38:07.799] 
[16:38:07.800]    Creating an optimized production build ...
[16:38:07.910]    Using tsconfig file: ./tsconfig.next.json
[16:38:20.833]  ✓ Compiled successfully
[16:38:20.833]    Skipping validation of types
[16:38:20.834]    Skipping linting
[16:38:21.211]    Collecting page data ...
[16:38:22.293]    Generating static pages (0/11) ...
[16:38:22.580] 
   Generating static pages (2/11) 
[16:38:22.947] 
   Generating static pages (5/11) 
[16:38:23.109] 
   Generating static pages (8/11) 
[16:38:23.629] 
 ✓ Generating static pages (11/11) 
[16:38:24.055]    Finalizing page optimization ...
[16:38:24.055]    Collecting build traces ...
[16:38:31.813] RangeError: Maximum call stack size exceeded
[16:38:31.814]     at parse (/vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/compiled/micromatch/index.js:15:6313)
[16:38:31.814]     at picomatch.makeRe (/vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/compiled/micromatch/index.js:15:21670)
[16:38:31.814]     at picomatch (/vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/compiled/micromatch/index.js:15:19637)
[16:38:31.814]     at /vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/compiled/micromatch/index.js:15:19294
[16:38:31.814]     at Array.map (<anonymous>)
[16:38:31.815]     at picomatch (/vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/compiled/micromatch/index.js:15:19286)
[16:38:31.815]     at micromatch.isMatch (/vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/compiled/micromatch/index.js:15:1090)
[16:38:31.815]     at /vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/build/collect-build-traces.js:245:48
[16:38:31.815]     at shouldIgnore (/vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/build/collect-build-traces.js:75:9)
[16:38:31.816]     at /vercel/path0/node_modules/.pnpm/next@14.0.4_react-dom@18.2.0_react@18.2.0_sass@1.69.7/node_modules/next/dist/build/collect-build-traces.js:86:23
[16:38:31.862]  ELIFECYCLE  Command failed with exit code 1.
[16:38:31.892]  ELIFECYCLE  Command failed with exit code 1.
[16:38:31.920] Error: Command "cd ../ && pnpm run build && cd ./web && pnpm run build:next" exited with 1
[16:38:32.463] 

@pkerschbaum
Copy link

pkerschbaum commented Jan 13, 2024

Oh, I just found https://github.com/orgs/vercel/discussions/5449, and they are investigating the issue already (comment) - I suggest to close this ticket here.

@lovell
Copy link
Owner

lovell commented Jan 13, 2024

Thanks, this definitely looks like an existing Next.js problem that a sharp upgrade has exposed rather than caused.

Pinning dependencies to avoid this problem is kicking the proverbial can down the road; another dependency update may come along and trigger it. Please ensure Vercel support are aware of this, and that the "accepted answer" is a temporary workaround rather than a solution.

@lovell
Copy link
Owner

lovell commented Jan 16, 2024

Given there are further reports erroneously being opened against sharp, I had a quick look at the Next.js source code and there is very clearly existing recursive behaviour within the shouldIgnore function of its build trace logic.

https://github.com/vercel/next.js/blob/dc394483b807e5e111c175ad9afd1f09220da7ce/packages/next/src/build/collect-build-traces.ts#L59

Please see #3944 for why unbound recursion is a bad idea 😜

ijjk added a commit to vercel/next.js that referenced this issue Jan 16, 2024
This ensures when a dependency has a recursive require our should ignore
handling doesn't accidentally loop back and forth.

x-ref: lovell/sharp#3944

Closes NEXT-2121
@lovell
Copy link
Owner

lovell commented Jan 16, 2024

It looks like vercel/next.js#60740 uses tail-call optimisation to help solve this 🎉

@swarnava
Copy link

Hi,

The fix is now available in v14.0.5-canary.60 of Next.js where you can use latest sharp package.

@liamrathke
Copy link

I ran into what seems to be a similar error, but with a different package throwing errors; not sure exactly what was causing the issue (Next or Sharp), but posting here in case someone else runs into this:

test-app:build: RangeError: Maximum call stack size exceeded
test-app:build:
test-app:build: RangeError: Maximum call stack size exceeded
test-app:build:     at walk (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:59747)
test-app:build:     at Object.BinaryExpression (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:60591)
test-app:build:     at walk (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:59784)
test-app:build:     at Object.BinaryExpression (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:60591)
test-app:build:     at walk (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:59784)
test-app:build:     at Object.BinaryExpression (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:60591)
test-app:build:     at walk (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:59784)
test-app:build:     at Object.BinaryExpression (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:60591)
test-app:build:     at walk (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:59784)
test-app:build:     at Object.BinaryExpression (test-monorepo/node_modules/next/dist/compiled/@vercel/nft/index.js:1:60591)
test-app:build:  ELIFECYCLE  Command failed with exit code 1.
test-app:build: ERROR: command finished with error: command (test-monorepo/apps/test-app) /opt/homebrew/bin/pnpm run build exited (1)
test-app#build: command (test-monorepo/apps/test-app) /opt/homebrew/bin/pnpm run build exited (1)

 Tasks:    0 successful, 1 total
Cached:    0 cached, 1 total
  Time:    1m51.67s
Failed:    test-app#build

The build step was breaking on ARM macOS with Node 22, Next 14.2.1, and Sharp ^0.33.3 (worked fine in other non-macOS environments). I realized that we don't actually use any of Next's image optimization features, so I "solved" the issue by removing Sharp from the package.json.

vercel/next.js#58372 (comment)

@lovell
Copy link
Owner

lovell commented May 8, 2024

@liamrathke Although it might appear to be related to sharp, this issue was/is in the @vercel/nft package, and you are seeing effects rather than cause.

Please ensure you're using the latest version of @vercel/nft, currently 0.26.4, which can be checked by running npm ls @vercel/nft.

If you're still having problems, you've probably run into vercel/nft#402

@Qvantitative
Copy link

@liamrathke Although it might appear to be related to sharp, this issue was/is in the @vercel/nft package, and you are seeing effects rather than cause.

Please ensure you're using the latest version of @vercel/nft, currently 0.26.4, which can be checked by running npm ls @vercel/nft.

If you're still having problems, you've probably run into vercel/nft#402

this is the solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants