facebook / facebook/docusaurus

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

Đang mở
#9,907 11 bình luận 0 reaction 0 người được giao Xem trên GitHub
bug
Ngôn ngữ chính
TypeScript
Star
66.2k
Fork
10k
Merge trung bình
1 ngày 3 giờ
Pull request đã merge (30 ngày)
52

Mô tả

### 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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.