GitbookIO / gitbook

The open source frontend for GitBook doc sites
https://www.gitbook.com
GNU General Public License v3.0
27.14k stars 3.87k forks source link

gitbook 3 pre13 generation error : RangeError: Maximum call stack size exceeded #1279

Closed prudhomm closed 7 months ago

prudhomm commented 8 years ago

Note that the file in quite is relatively complex with a lot of math and table but this was never an issue with gitbook < 3.

You are using a pre-release of GitBoook
To use version 3, the book.json should explicit set "gitbook" to ">=3.0.0-pre.0"

Downloading source
Extracting source
GitBook version is 3.0.0-pre.13 
Tweaking book.json
Installing plugins
info: installing 10 plugins using npm@3.8.8 
info:  
info: installing plugin "anchors" 
info: install plugin "anchors" (*) from NPM with version 0.6.0 
/tmp/book
└─┬ gitbook-plugin-anchors@0.6.0 
  ├─┬ cheerio@0.20.0 
  │ ├─┬ css-select@1.2.0 
  │ │ ├── boolbase@1.0.0 
  │ │ ├── css-what@2.1.0 
  │ │ ├── domutils@1.5.1 
  │ │ └── nth-check@1.0.1 
  │ ├─┬ dom-serializer@0.1.0 
  │ │ └── domelementtype@1.1.3 
  │ ├── entities@1.1.1 
  │ ├─┬ htmlparser2@3.8.3 
  │ │ ├── domelementtype@1.3.0 
  │ │ ├── domhandler@2.3.0 
  │ │ ├── entities@1.0.0 
  │ │ └─┬ readable-stream@1.1.14 
  │ │   ├── core-util-is@1.0.2 
  │ │   ├── inherits@2.0.1 
  │ │   ├── isarray@0.0.1 
  │ │   └── string_decoder@0.10.31 
  │ └─┬ jsdom@7.2.2 
  │   ├── abab@1.0.3 
  │   ├── acorn@2.7.0 
  │   ├── acorn-globals@1.0.9 
  │   ├── cssom@0.3.1 
  │   ├── cssstyle@0.2.34 
  │   ├─┬ escodegen@1.8.0 
  │   │ ├── esprima@2.7.2 
  │   │ ├── estraverse@1.9.3 
  │   │ ├── esutils@2.0.2 
  │   │ ├─┬ optionator@0.8.1 
  │   │ │ ├── deep-is@0.1.3 
  │   │ │ ├── fast-levenshtein@1.1.3 
  │   │ │ ├── levn@0.3.0 
  │   │ │ ├── prelude-ls@1.1.2 
  │   │ │ ├── type-check@0.3.2 
  │   │ │ └── wordwrap@1.0.0 
  │   │ └─┬ source-map@0.2.0 
  │   │   └── amdefine@1.0.0 
  │   ├── nwmatcher@1.3.7 
  │   ├── parse5@1.5.1 
  │   ├─┬ request@2.72.0 
  │   │ ├── aws-sign2@0.6.0 
  │   │ ├─┬ aws4@1.3.2 
  │   │ │ └─┬ lru-cache@4.0.1 
  │   │ │   ├── pseudomap@1.0.2 
  │   │ │   └── yallist@2.0.0 
  │   │ ├─┬ bl@1.1.2 
  │   │ │ └─┬ readable-stream@2.0.6 
  │   │ │   ├── isarray@1.0.0 
  │   │ │   ├── process-nextick-args@1.0.7 
  │   │ │   └── util-deprecate@1.0.2 
  │   │ ├── caseless@0.11.0 
  │   │ ├─┬ combined-stream@1.0.5 
  │   │ │ └── delayed-stream@1.0.0 
  │   │ ├── extend@3.0.0 
  │   │ ├── forever-agent@0.6.1 
  │   │ ├─┬ form-data@1.0.0-rc4 
  │   │ │ └── async@1.5.2 
  │   │ ├─┬ har-validator@2.0.6 
  │   │ │ ├─┬ chalk@1.1.3 
  │   │ │ │ ├── ansi-styles@2.2.1 
  │   │ │ │ ├── escape-string-regexp@1.0.5 
  │   │ │ │ ├─┬ has-ansi@2.0.0 
  │   │ │ │ │ └── ansi-regex@2.0.0 
  │   │ │ │ ├── strip-ansi@3.0.1 
  │   │ │ │ └── supports-color@2.0.0 
  │   │ │ ├─┬ commander@2.9.0 
  │   │ │ │ └── graceful-readlink@1.0.1 
  │   │ │ ├─┬ is-my-json-valid@2.13.1 
  │   │ │ │ ├── generate-function@2.0.0 
  │   │ │ │ ├─┬ generate-object-property@1.2.0 
  │   │ │ │ │ └── is-property@1.0.2 
  │   │ │ │ ├── jsonpointer@2.0.0 
  │   │ │ │ └── xtend@4.0.1 
  │   │ │ └─┬ pinkie-promise@2.0.1 
  │   │ │   └── pinkie@2.0.4 
  │   │ ├─┬ hawk@3.1.3 
  │   │ │ ├── boom@2.10.1 
  │   │ │ ├── cryptiles@2.0.5 
  │   │ │ ├── hoek@2.16.3 
  │   │ │ └── sntp@1.0.9 
  │   │ ├─┬ http-signature@1.1.1 
  │   │ │ ├── assert-plus@0.2.0 
  │   │ │ ├─┬ jsprim@1.2.2 
  │   │ │ │ ├── extsprintf@1.0.2 
  │   │ │ │ ├── json-schema@0.2.2 
  │   │ │ │ └── verror@1.3.6 
  │   │ │ └─┬ sshpk@1.8.3 
  │   │ │   ├── asn1@0.2.3 
  │   │ │   ├── assert-plus@1.0.0 
  │   │ │   ├─┬ dashdash@1.13.1 
  │   │ │   │ └── assert-plus@1.0.0 
  │   │ │   ├── ecc-jsbn@0.1.1 
  │   │ │   ├─┬ getpass@0.1.6 
  │   │ │   │ └── assert-plus@1.0.0 
  │   │ │   ├── jodid25519@1.0.2 
  │   │ │   ├── jsbn@0.1.0 
  │   │ │   └── tweetnacl@0.13.3 
  │   │ ├── is-typedarray@1.0.0 
  │   │ ├── isstream@0.1.2 
  │   │ ├── json-stringify-safe@5.0.1 
  │   │ ├─┬ mime-types@2.1.11 
  │   │ │ └── mime-db@1.23.0 
  │   │ ├── node-uuid@1.4.7 
  │   │ ├── oauth-sign@0.8.2 
  │   │ ├── qs@6.1.0 
  │   │ ├── stringstream@0.0.5 
  │   │ └── tunnel-agent@0.4.3 
  │   ├── sax@1.2.1 
  │   ├── symbol-tree@3.1.4 
  │   ├── tough-cookie@2.2.2 
  │   ├── webidl-conversions@2.0.1 
  │   ├─┬ whatwg-url-compat@0.6.5 
  │   │ └── tr46@0.0.3 
  │   └── xml-name-validator@2.0.1 
  └── lodash@4.11.2 

info: >> plugin "anchors" installed with success 
info:  
info: installing plugin "include-codeblock" 
info: install plugin "include-codeblock" (*) from NPM with version 1.8.2 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
└─┬ gitbook-plugin-include-codeblock@1.8.2 
  └── language-map@1.1.2 

info: >> plugin "include-codeblock" installed with success 
info:  
info: installing plugin "include-highlight" 
info: install plugin "include-highlight" (*) from NPM with version 0.2.0 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-include-codeblock@1.8.2 
└─┬ gitbook-plugin-include-highlight@0.2.0 
  ├── fs@0.0.2 
  ├─┬ path@0.12.7 
  │ ├── process@0.11.2 
  │ └── util@0.10.3 
  └── q@1.4.1 

info: >> plugin "include-highlight" installed with success 
info:  
info: installing plugin "ga" 
info: install plugin "ga" (*) from NPM with version 1.0.1 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
└── gitbook-plugin-include-highlight@0.2.0 

info: >> plugin "ga" installed with success 
info:  
info: installing plugin "richquotes" 
info: install plugin "richquotes" (*) from NPM with version 0.0.7 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
├── gitbook-plugin-include-highlight@0.2.0 
└─┬ gitbook-plugin-richquotes@0.0.7 
  └─┬ cheerio@0.19.0 
    ├─┬ css-select@1.0.0 
    │ ├── css-what@1.0.0 
    │ └── domutils@1.4.3 
    └── lodash@3.10.1 

info: >> plugin "richquotes" installed with success 
info:  
info: installing plugin "toc" 
info: install plugin "toc" (*) from NPM with version 0.0.1 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
├── gitbook-plugin-include-highlight@0.2.0 
├── gitbook-plugin-richquotes@0.0.7 
└─┬ gitbook-plugin-toc@0.0.1 
  └─┬ marked-toc@0.2.8 
    ├─┬ fs-utils@0.5.0 
    │ ├── async@0.9.2 
    │ ├─┬ delete@0.1.5 
    │ │ ├── is-path-cwd@0.1.0 
    │ │ ├─┬ is-path-in-cwd@0.1.1 
    │ │ │ └─┬ is-path-inside@0.1.0 
    │ │ │   └── path-is-inside@1.0.1 
    │ │ └─┬ rimraf@2.5.2 
    │ │   └─┬ glob@7.0.3 
    │ │     ├── minimatch@3.0.0 
    │ │     └── path-is-absolute@1.0.0 
    │ ├─┬ extend-shallow@0.1.1 
    │ │ └── array-slice@0.2.3 
    │ ├─┬ globby@0.1.1 
    │ │ ├── array-differ@0.1.0 
    │ │ ├─┬ array-union@0.1.0 
    │ │ │ └── array-uniq@0.1.1 
    │ │ ├── async@0.9.2 
    │ │ └─┬ glob@4.5.3 
    │ │   ├─┬ inflight@1.0.4 
    │ │   │ └── wrappy@1.0.1 
    │ │   ├─┬ minimatch@2.0.10 
    │ │   │ └─┬ brace-expansion@1.1.4 
    │ │   │   ├── balanced-match@0.4.1 
    │ │   │   └── concat-map@0.0.1 
    │ │   └── once@1.3.3 
    │ ├── graceful-fs@3.0.8 
    │ ├─┬ is-absolute@0.1.7 
    │ │ └── is-relative@0.1.3 
    │ ├─┬ js-yaml@3.6.0 
    │ │ └─┬ argparse@1.0.7 
    │ │   └── sprintf-js@1.0.3 
    │ ├── kind-of@0.1.2 
    │ └─┬ relative@0.1.6 
    │   └── normalize-path@0.1.1 
    ├─┬ gray-matter@0.5.3 
    │ ├── coffee-script@1.10.0 
    │ ├─┬ delims@0.4.2 
    │ │ ├─┬ arrayify-compact@0.1.0 
    │ │ │ └── array-flatten@2.1.0 
    │ │ └── object-pick@0.1.2 
    │ ├── lodash@2.4.2 
    │ ├─┬ mixin-deep@0.1.0 
    │ │ ├─┬ for-own@0.1.4 
    │ │ │ └── for-in@0.1.5 
    │ │ └── is-plain-object@0.1.0 
    │ ├── toml@2.3.0 
    │ └─┬ verbalize@0.1.2 
    │   └─┬ chalk@0.4.0 
    │     ├── ansi-styles@1.0.0 
    │     ├── has-color@0.1.7 
    │     └── strip-ansi@0.1.1 
    ├── lodash@2.4.2 
    ├── marked@0.3.0 
    ├─┬ template@0.1.8 
    │ ├── delims@0.1.4 
    │ ├─┬ fs-utils@0.4.3 
    │ │ ├── async@0.6.2 
    │ │ ├─┬ globule@0.2.0 
    │ │ │ ├─┬ glob@3.2.11 
    │ │ │ │ └── minimatch@0.3.0 
    │ │ │ ├── lodash@2.4.2 
    │ │ │ └─┬ minimatch@0.2.14 
    │ │ │   ├── lru-cache@2.7.3 
    │ │ │   └── sigmund@1.0.1 
    │ │ ├── graceful-fs@2.0.3 
    │ │ ├─┬ js-yaml@3.0.2 
    │ │ │ ├─┬ argparse@0.1.16 
    │ │ │ │ ├── underscore@1.7.0 
    │ │ │ │ └── underscore.string@2.4.0 
    │ │ │ └── esprima@1.0.4 
    │ │ ├── mkdirp@0.3.5 
    │ │ └── rimraf@2.2.8 
    │ ├── lodash@2.4.2 
    │ └── underscore.string@2.3.3 
    └─┬ uslug@1.0.4 
      └── unorm@1.4.1 

info: >> plugin "toc" installed with success 
info:  
info: installing plugin "expandable-chapters" 
info: install plugin "expandable-chapters" (*) from NPM with version 0.1.6 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-expandable-chapters@0.1.6 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
├── gitbook-plugin-include-highlight@0.2.0 
├── gitbook-plugin-richquotes@0.0.7 
└── gitbook-plugin-toc@0.0.1 

info: >> plugin "expandable-chapters" installed with success 
info:  
info: installing plugin "unicodecss" 
info: install plugin "unicodecss" (*) from NPM with version 0.0.8 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-expandable-chapters@0.1.6 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
├── gitbook-plugin-include-highlight@0.2.0 
├── gitbook-plugin-richquotes@0.0.7 
├── gitbook-plugin-toc@0.0.1 
└── gitbook-plugin-unicodecss@0.0.8 

info: >> plugin "unicodecss" installed with success 
info:  
info: installing plugin "mathjax" 
info: install plugin "mathjax" (*) from NPM with version 1.1.0 
make: Entering directory `/tmp/book/node_modules/contextify/build'
  CXX(target) Release/obj.target/contextify/src/contextify.o
  SOLINK_MODULE(target) Release/obj.target/contextify.node
  COPY Release/contextify.node
make: Leaving directory `/tmp/book/node_modules/contextify/build'
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-expandable-chapters@0.1.6 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
├── gitbook-plugin-include-highlight@0.2.0 
├─┬ gitbook-plugin-mathjax@1.1.0 
│ ├── crc@3.4.0 
│ └─┬ MathJax-node@0.3.1 
│   ├─┬ jsdom@3.1.1 
│   │ ├── browser-request@0.3.3 
│   │ ├─┬ contextify@0.1.15 
│   │ │ ├── bindings@1.2.1 
│   │ │ └── nan@2.3.3 
│   │ ├── xml-name-validator@1.0.0 
│   │ └── xmlhttprequest@1.8.0 
│   ├── MathJax@2.5.1-mjnode 
│   ├─┬ speech-rule-engine@0.9.2 
│   │ ├─┬ xml-mapping@1.7.1 
│   │ │ ├── sax@0.4.2 
│   │ │ └── xml-writer@1.6.0 
│   │ ├── xmldom@0.1.22 
│   │ └── xpath@0.0.23 
│   └─┬ yargs@4.7.0 
│     ├── camelcase@2.1.1 
│     ├─┬ cliui@3.2.0 
│     │ └── wrap-ansi@2.0.0 
│     ├── decamelize@1.2.0 
│     ├─┬ lodash.assign@4.0.8 
│     │ ├── lodash.keys@4.0.6 
│     │ └── lodash.rest@4.0.2 
│     ├─┬ os-locale@1.4.0 
│     │ └─┬ lcid@1.0.0 
│     │   └── invert-kv@1.0.0 
│     ├─┬ pkg-conf@1.1.2 
│     │ ├─┬ find-up@1.1.2 
│     │ │ └── path-exists@2.1.0 
│     │ ├─┬ load-json-file@1.1.0 
│     │ │ ├── graceful-fs@4.1.4 
│     │ │ ├─┬ parse-json@2.2.0 
│     │ │ │ └─┬ error-ex@1.3.0 
│     │ │ │   └── is-arrayish@0.2.1 
│     │ │ ├── pify@2.3.0 
│     │ │ └─┬ strip-bom@2.0.0 
│     │ │   └── is-utf8@0.2.1 
│     │ ├── object-assign@4.1.0 
│     │ └── symbol@0.2.2 
│     ├─┬ read-pkg-up@1.0.1 
│     │ └─┬ read-pkg@1.1.0 
│     │   ├─┬ normalize-package-data@2.3.5 
│     │   │ ├── hosted-git-info@2.1.4 
│     │   │ ├─┬ is-builtin-module@1.0.0 
│     │   │ │ └── builtin-modules@1.1.1 
│     │   │ ├── semver@5.1.0 
│     │   │ └─┬ validate-npm-package-license@3.0.1 
│     │   │   ├─┬ spdx-correct@1.0.2 
│     │   │   │ └── spdx-license-ids@1.2.1 
│     │   │   └─┬ spdx-expression-parse@1.0.2 
│     │   │     └── spdx-exceptions@1.0.4 
│     │   └─┬ path-type@1.1.0 
│     │     └── graceful-fs@4.1.4 
│     ├── require-main-filename@1.0.1 
│     ├─┬ string-width@1.0.1 
│     │ ├─┬ code-point-at@1.0.0 
│     │ │ └── number-is-nan@1.0.0 
│     │ └── is-fullwidth-code-point@1.0.0 
│     ├── window-size@0.2.0 
│     ├── y18n@3.2.1 
│     └── yargs-parser@2.4.0 
├── gitbook-plugin-richquotes@0.0.7 
├── gitbook-plugin-toc@0.0.1 
└── gitbook-plugin-unicodecss@0.0.8 

info: >> plugin "mathjax" installed with success 
info:  
info: installing plugin "comment" 
info: install plugin "comment" (*) from NPM with version 1.0.0 
/tmp/book
├── gitbook-plugin-anchors@0.6.0 
├── gitbook-plugin-comment@1.0.0 
├── gitbook-plugin-expandable-chapters@0.1.6 
├── gitbook-plugin-ga@1.0.1 
├── gitbook-plugin-include-codeblock@1.8.2 
├── gitbook-plugin-include-highlight@0.2.0 
├── gitbook-plugin-mathjax@1.1.0 
├── gitbook-plugin-richquotes@0.0.7 
├── gitbook-plugin-toc@0.0.1 
└── gitbook-plugin-unicodecss@0.0.8 

info: >> plugin "comment" installed with success 
Building Site, will upload
info: 15 plugins are installed 
info: loading plugin "anchors"... OK 
info: loading plugin "include-codeblock"... OK 
info: loading plugin "include-highlight"... OK 
info: loading plugin "ga"... OK 
info: loading plugin "richquotes"... OK 
info: loading plugin "toc"... OK 
info: loading plugin "expandable-chapters"... OK 
info: loading plugin "unicodecss"... OK 
info: loading plugin "mathjax"... OK 
info: loading plugin "comment"... OK 
info: loading plugin "highlight"... OK 
info: loading plugin "lunr"... OK 
info: loading plugin "sharing"... OK 
info: loading plugin "fontsettings"... OK 
info: loading plugin "theme-default"... OK 
info: found 74 pages 
info: found 147 asset files 
warn: "options" property is deprecated, use config.get(key) instead 
warn: "sections" property is deprecated, use page.content instead 
warn: "this.generator" property is deprecated, use "this.output.name" instead 
warn: "navigation" property is deprecated 
warn: "book" property is deprecated, use "this" directly instead 
asciidoctor: WARNING: <stdin>: line 42: section title out of sequence: expected level 1, got level 2
error: error while generating page "QuickReference/keywords.adoc": 

Template render error: (QuickReference/keywords.adoc)
  RangeError: Maximum call stack size exceeded
SamyPesse commented 8 years ago

Can you run it with --debug or do you have a link to your book (so that I can debug the issue locally) ?

prudhomm commented 8 years ago

here it is https://github.com/feelpp/feelpp-book or https://www.gitbook.com/book/feelpp/feelpp-book/details

SamyPesse commented 8 years ago

After investigation this issue locally: It looks like this is happening during parsing by Nunjucks, the page is huge and contains a lot of {% math %} block (replaced from $$...$$).

I'm looking on implementing a fix in Nunjucks, but it might not be easy (Nunjuck's parser is syncchronous, the best solution will be to have an async parser with some setImmediate to avoid exceeding the call stack in the event loop).

SamyPesse commented 8 years ago

I've open an issue on Nunjucks: https://github.com/mozilla/nunjucks/issues/749

prudhomm commented 8 years ago

@SamyPesse I have split the file with lots of formulas and now it passes through however the math rendering is broken with mathjax #1286

jeffrey-cochran commented 6 years ago

I'm encountering the same issue, and I believe the cause is very similar (too many mathjax equations). As far as layout is concerned, it wouldn't make a lot of sense to break up my file into multiple files.

@SamyPesse I noticed there was a discussion in 2015 regarding a similar issue for the search plugin #1009 for which it was suggested that folks change the search's max index size. Is there anything analogous for documents that require large amounts of mathjax rendering?

The trouble-maker is chapter1.md of this book: https://www.gitbook.com/book/jeffcochran/the-nurbs-book-solutions-unofficial/details

viogp commented 5 years ago

Hi, I'm encountering the same issue with one file with multiple equations (https://msm.gitbook.io/msm/introduction-1/newman_model). When I run gitbook --debug serve (CLI version: 2.3.2 GitBook version: 3.2.3, running in a Windows 10 machine) I get:

Template render error: (C:[...]Newman_model.md)
  RangeError: Maximum call stack size exceeded
Template render error: (C:[...]Newman_model.md)
  RangeError: Maximum call stack size exceeded
    at Object.exports.prettifyError (C:[...]\.gitbook\versions\3.2.3\node_modules\nunjucks\src\lib.js:34:15)
    at new_cls.render (C:[...].gitbook\versions\3.2.3\node_modules\nunjucks\src\environment.js:469:27)
    at new_cls.renderString (C:[...]\.gitbook\versions\3.2.3\node_modules\nunjucks\src\environment.js:327:21)
    at Promise.apply (C:[...]\.gitbook\versions\3.2.3\node_modules\q\q.js:1165:26)
    at Promise.promise.promiseDispatch (C:[...]\.gitbook\versions\3.2.3\node_modules\q\q.js:788:41)
    at C:[...]\.gitbook\versions\3.2.3\node_modules\q\q.js:1391:14
    at runSingle (C:[...]\.gitbook\versions\3.2.3\node_modules\q\q.js:137:13)
    at flush (C:[...]\.gitbook\versions\3.2.3\node_modules\q\q.js:125:13)
    at process._tickCallback (internal/process/next_tick.js:61:11)

However, the files are rendered properly within Gitbook.io