Skip to main content

22 posts tagged with "React"

View All Tags

· One min read
Roger Jiang

Docusarus start breaks during client building - ambigious issue with JSON parsing by Docusaurus' MDX Loader

[ERROR] SyntaxError: Unexpected token m in JSON at position 3630
at JSON.parse (<anonymous>)
at Object.mdxLoader (C:\Users\Z\react-dev\rjdb-map\node_modules\@docusaurus\mdx-loader\lib\loader.js:190:16)
[INFO] Docusaurus version: 2.3.1
Node version: v18.14.1
error Command failed with exit code 1.

· 5 min read
Roger Jiang

If you have more than 5000 pages on your docusaurus site, prepare for a whole world of pain. The build times will reach multiple hours, assuming it doesn't crash before emitting all files. The default docusaurus settings is unusable and must be configured properly.

There appears to be a large memory overhead when building SSG with docusaurus. This is perhaps by design, since loading everything into memory can improve performance. The only way to fix this is to raise the node memory size, configure a more efficient webpack builder through plugins/cache & reducing the number of pages.

TL;DR Critical checklist to follow, if you want to build huge sites with Docusaurus

  1. Switch to swc-loader or esbuild-loader - this will cut down on the build times by 50% but also improves memory usage
  2. Run the build on a machine with at least 16GB RAM. Recommended 32GB.
  3. Raise node.js old space heap size limit to 12GB+
  4. Reduce DOCUSAURUS_SSR_CONCURRENCY (ie to 4)
  5. Set up webpack caching
  6. Reduce/consolidate the number of pages for /docs & /blog
  7. If all else fails, give up on Docusaurus & migrate to Nextra/Next.js for ISR
  8. Disable source_maps & BundleAnalyzerPlugin