facebook / facebook/docusaurus

RangeError: Invalid string length when building with a very large number of blogs

未关闭
#9,907 11 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
bug
主要语言
TypeScript
星标
66.2k
派生
10k
平均合并
1 天 3 小时
30 天内合并 PR
52

描述

### Have you read the Contributing Guidelines on issues?

- [X] I have read the [Contributing Guidelines on issues](https://github.com/facebook/docusaurus/blob/main/CONTRIBUTING.md#issues).

### Prerequisites

- [X] I'm using the latest version of Docusaurus.
- [X] I have tried the `npm run clear` or `yarn clear` command.
- [X] I have tried `rm -rf node_modules yarn.lock package-lock.json` and re-installing packages.
- [X] I have tried creating a repro with https://new.docusaurus.io.
- [X] I have read the console error message carefully (if applicable).

### Description

docusaurus build returns `RangeError: Invalid string length` when building the website with a very large number of blogs (~30K)

Error:
```
$ NODE_OPTIONS=--max_old_space_size=12288 npm run build -- --locale fa

> sample-app-com@0.0.0 build
> docusaurus build --locale fa

[INFO] [fa] Creating an optimized production build...

Error: Unable to build website for locale fa.
at tryToBuildLocale (/Users/ardavan/Documents/sample.com/node_modules/@docusaurus/core/lib/commands/build.js:55:19) {
[cause]: RangeError: Invalid string length
at JSON.stringify ()
at Object.contentLoaded (/Users/ardavan/Documents/sample.com/node_modules/@docusaurus/plugin-content-blog/lib/index.js:135:104)
at /Users/ardavan/Documents/sample.com/node_modules/@docusaurus/core/lib/server/plugins/index.js:99:22
at async Promise.all (index 3)
at async loadPlugins (/Users/ardavan/Documents/sample.com/node_modules/@docusaurus/core/lib/server/plugins/index.js:63:5)
at async load (/Users/ardavan/Documents/sample.com/node_modules/@docusaurus/core/lib/server/index.js:76:58)
at async buildLocale (/Users/ardavan/Documents/sample.com/node_modules/@docusaurus/core/lib/commands/build.js:95:19)
at async tryToBuildLocale (/Users/ardavan/Documents/sample.com/node_modules/@docusaurus/core/lib/commands/build.js:46:20)
}

[INFO] Docusaurus version: 3.1.1
Node version: v20.11.0
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
```

Looking at the code, it looks like `JSON.stringify({ blogPosts: listedBlogPosts }` is the problematic part

### Reproducible demo

_No response_

### Steps to reproduce

- Generate a lot of blog posts (~30K)
- run build

### Expected behavior

- Should build the website without any issues

### Actual behavior

it throws `RangeError: Invalid string length`

### Your environment

- Public source code:
- Public site URL:
- Docusaurus version used:
- Environment name and version (e.g. Chrome 89, Node.js 16.4):
Docusaurus version: 3.1.1
Node version: v20.11.0
- Operating system and version (e.g. Ubuntu 20.04.2 LTS):
macOS 14.3.1 (23D60)

### Self-service

- [ ] I'd be willing to fix this bug myself.

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。