gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.28k stars 10.31k forks source link

Gatsby V4 build fails with: RangeError: Maximum call stack size exceeded #34879

Closed NICHTJ3 closed 2 years ago

NICHTJ3 commented 2 years ago

Preliminary Checks

Description

What

gatsby build is failing with RangeError: Maximum call stack size exceeded I believe this is related to code added for DSG here.

Let me know if any more info is needed and I'll do my best to supply it 😄 I've been unable to repro in any generated projects even with the same plugins so all I can say is there are a lot of pages in the project so it's probably be related to the size of data

NOTE: gatsby develop does not fail.

Reproduction Link

https://github.com/gatsbyjs/gatsby

Steps to Reproduce

  1. Run gatsby build ...

Expected Result

Build passes

Actual Result

success Execute page configs - 14.154s

 ERROR

Maximum call stack size exceeded

  RangeError: Maximum call stack size exceeded

  - RegExp.exec

  - source-map-support.js:227 retrieveSourceMapURL
    [@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip]/[@cspotcode]/source-map-support/source-map-support.js:227:21

  - source-map-support.js:239 Array.<anonymous>
    [@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip]/[@cspotcode]/source-map-support/source-map-support.js:239:26

  - source-map-support.js:138
    [@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip]/[@cspotcode]/source-map-support/source-map-support.js:138:32

  - source-map-support.js:269 mapSourcePosition
    [@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip]/[@cspotcode]/source-map-support/source-map-support.js:269:21

  - source-map-support.js:461 wrapCallSite
    [@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip]/[@cspotcode]/source-map-support/source-map-support.js:461:20

  - source-map-support.js:541 Function.prepareStackTrace
    [@cspotcode-source-map-support-npm-0.7.0-456c3ea2ce-9faddda775.zip]/[@cspotcode]/source-map-support/source-map-support.js:541:41

  - errors.js:110 maybeOverridePrepareStackTrace
    internal/errors.js:110:29

  - errors.js:89 prepareStackTrace
    internal/errors.js:89:5

  - stack-trace.js:21 Object.exports.parse
    [stack-trace-npm-0.0.10-9460b173e1-473036ad32.zip]/[stack-trace]/lib/stack-trace.js:21:12

  - construct-error.js:41 constructError
    [gatsby-cli-npm-4.7.0-e3bcfca61c]/[gatsby-cli]/lib/structured-errors/construct-error.js:41:95

  - reporter.js:176 Reporter.error
    [gatsby-cli-npm-4.7.0-e3bcfca61c]/[gatsby-cli]/lib/reporter/reporter.js:176:57

  - reporter.js:103 Reporter.panic
    [gatsby-cli-npm-4.7.0-e3bcfca61c]/[gatsby-cli]/lib/reporter/reporter.js:103:32

  - build.ts:240 build
    [gatsby-virtual-dacdd53df8]/[gatsby]/src/commands/build.ts:240:14

Environment

System:
    OS: macOS 12.2.1
    CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.17.3 - /private/var/folders/l7/ytmsmq8n28g2jrrrfjk074m40000gp/T/xfs-d25801e9/node
    Yarn: 3.0.2 - /private/var/folders/l7/ytmsmq8n28g2jrrrfjk074m40000gp/T/xfs-d25801e9/yarn
    npm: 6.14.13 - ~/Library/Caches/fnm_multishells/21239_1645221379493/bin/npm
  Languages:
    Python: 2.7.18 - /usr/bin/python
  Browsers:
    Chrome: 98.0.4758.102
    Safari: 15.3

Config Flags

No response

NICHTJ3 commented 2 years ago

So I added some logging to the build and found we actually only have 324 pages being made which doesn't seem like much

tyhopp commented 2 years ago

Hi @NICHTJ3!

Sorry to hear you're running into an issue. To help us best begin debugging the underlying cause, it is incredibly helpful if you're able to create a minimal reproduction. This is a simplified example of the issue that makes it clear and obvious what the issue is and how we can begin to debug it.

If you're up for it, we'd very much appreciate if you could provide a minimal reproduction and we'll be able to take another look.

Thanks for using Gatsby! 💜

NICHTJ3 commented 2 years ago

Hey @tyhopp,

I'll create a minimal reproduction later on but it appears to actually be a bug on my end to do with my template in gatsby-(ssr/browser).js, but if I comment out the method the errors being thrown from in gatsby here I get a slightly more useful error message.

success Writing page-data.json files to public directory - 0.094s - 27/27 287.95/s

 ERROR

Page data from page-data.json for the failed page "/edms/xero-developer-update-july-2021/": {
  "componentChunkName": "component---src-templates-edm-edm-container-tsx",
  "path": "/edms/Xero-Developer-Update-July-2021/",
  "result": {
    .......
  }

}

failed Building static HTML for pages - 2.409s

 ERROR #95313

Building static HTML failed for path "/edms/xero-developer-update-july-2021/"

See our docs page for more info on this error: https://gatsby.dev/debug-html
NICHTJ3 commented 2 years ago

This was once again an issue with react-helmet, somewhat related to this issue here. I'm not sure if there's a better way to report these kinds of errors but I'm going to close this issue for now but it might still help someone narrow it down 😄

tyhopp commented 2 years ago

@NICHTJ3 Thanks for sharing the result, glad you were able to resolve it!

NICHTJ3 commented 2 years ago

Okay, so after days of debugging I figured out what this was actually being caused by. For some reason circular imports just started breaking the codebase I assume it was from a babel/webpack update or something that happened at the same time but replacing imports in components that import from the same barrel (index.tsx) that they're exported from fixed this 🥲. Turns out the dev server also was erroring but only in the browser window and only on pages that used the components 🤦

stevepepple commented 2 years ago

I experienced that same as @NICHTJ3