OOM in pnpm monorepos due to recursive workspace symlink paths #128
Summary#
npx @tanstack/intent@latest list can OOM in large pnpm workspaces because dependency traversal appears to track packages by their raw resolved path rather than their canonical real path.
In a pnpm/Nx monorepo with many internal workspace packages, workspace packages are reachable through nested symlink chains like:
packages/pkg-a/node_modules/@internal/pkg-b/node_modules/@internal/pkg-c/node_modules/@internal/pkg-d/...
Those paths can point back to the same real workspace package locations, but each symlink-expanded path string is distinct. The scanner then revisits the same logical packages many times, causing path strings, package JSON cache entries, warnings, and visited-set entries to grow until V8 runs out of memory.
Repro / observed behavior#
NODE_OPTIONS='--max-old-space-size=512' npx @tanstack/intent@latest list
Observed with @tanstack/intent@0.0.40 on Node 24 in a large pnpm workspace:
FATAL ERROR: Ineffective mark-compacts near heap limit Allocation failed - JavaScript heap out of memory
--exclude '*' still OOMs because excludes are applied after scanning.
Debugging notes#
I locally instrumented the published dist/scanner-*.mjs from @tanstack/intent@0.0.40 and found:
- The crash happens inside
walkWorkspacePackages(), before rootnode_modulesscanning completes. - The scanner reached 37k+
package.jsonreads before crashing under the repeated nested workspace symlink chains. - A temporary patch that canonicalized resolved dependency dirs with
realpathSync()made the same scan complete under a 512 MB heap. - With that patch, the scan dropped to roughly 3k total
package.jsonreads and completed successfully.
The key issue seems to be this flow:
const depDir = resolveDepDir(depName, fromDir)
// depDir is used as a visited/cache identity without canonicalizing symlinks
Expected behavior#
The scanner should visit each logical package once, or at least avoid revisiting the same real filesystem package through different symlink paths.
Suggested fix#
Canonicalize package/dependency identity before using paths in visited/cache/dedupe sets, for example:
import { realpathSync } from 'node:fs'
import { resolve } from 'node:path'
function getFsIdentity(path) {
try {
return realpathSync(path)
} catch {
return resolve(path)
}
}
Then use that canonical identity consistently for dependency walk visited checks, package JSON cache keys, attempted package roots, and package variant/dedupe logic.
This should preserve pnpm support while preventing path explosion through workspace symlink chains.
Sign in to join this conversation.