Styleguidist server runs out of memory due to symlinks to directories
#1,194 opened on Nov 9, 2018
Repository metrics
- Stars
- (11,091 stars)
- PR merge metrics
- (PR metrics pending)
Description
Current behavior
If the component search path of Styleguidist includes at least three directories that symlink to each other (either directly or via subdirectories), running styleguidist server leads to a loop that'll terminate when node runs out of memory.
This took a while to determine; I came across the bug in a real-life project that's using Lerna to manage multiple packages, with a single package that re-exports all the others. There the symlinks were, roughly:
pkgA/node_modules/pkg -> ../../pkg
pkgB/node_modules/pkg -> ../../pkg
pkg/node_modules/pkgA -> ../../pkgA
pkg/node_modules/pkgB -> ../../pkgB
Dropping any one of those three packages will allow the server to run without problems. Running styleguidist build presents no problems.
To reproduce
I forked the example repo, and added a single commit to reproduce. Running npm install and then npm start will eventually lead to:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
Note that the symlinked directories don't need to be referred to by any of the components, they just need to be in the search path. Removing all Babel & Webpack config will not prevent the bug from manifesting. In fact, you can replace all of the components with a single .js consisting only of module.exports = {} and remove the Styleguidist config file, and still experience the same bug. Removing wildcards from the component search path will not help either, as long as the directories are next to a component.
Expected behavior
The Styleguidist server should not experience a FATAL ERROR.