Node.js "ENAMETOOLONG" - File Name Too Long During npm Operation in CI
An npm or filesystem operation hit the OS limit on path or argument length. Deeply nested dependency trees or very long generated paths overflow the limit and the operation fails with ENAMETOOLONG.
What this error means
An install, copy, or archive step fails with ENAMETOOLONG. It usually surfaces on a specific deeply nested path inside node_modules or a long generated filename.
Error: ENAMETOOLONG: name too long, open
'/work/repo/node_modules/a/node_modules/b/.../really-long-name.js'
errno: -36,
code: 'ENAMETOOLONG',
syscall: 'open'Common causes
A deeply nested, non-hoisted dependency tree
Without hoisting, nested node_modules paths grow long enough to exceed the OS path limit on certain entries.
A long argument list or generated path
A command that expands a very large glob into argv, or generates an overlong filename, can trip the system limit.
How to fix it
Hoist the dependency tree
Use a flatter install so nested paths stay short.
# npm flattens by default; for pnpm:
echo "node-linker=hoisted" >> .npmrc
pnpm installShorten the workspace path and avoid huge argv
Check out into a shorter base directory and avoid passing enormous file lists on the command line.
- Use a short CI working directory (avoid long nested paths).
- Replace giant globs with a manifest or
--files-fromstyle input. - Clean stale, deeply nested node_modules before reinstalling.
How to prevent it
- Keep the CI checkout path short.
- Prefer a hoisted/flat dependency layout.
- Avoid expanding very large globs directly into command arguments.