gemini-cli - 💡(How to fix) Fix Title: ENAMETOOLONG: name too long crash when Next.js compiler error is present in environment

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

When a Next.js compiler error exists in the dev environment (e.g., a missing default export), Gemini CLI crashes with an unhandled promise rejection: Error: ENAMETOOLONG: name too long, lstat '/lib/utils"; The CLI appears to be passing the raw Next.js compiler error message string (which includes multi-line code snippets) directly into lstat() as a file path via robustRealpath() → resolveToRealPath() → checkPermissions(). The OS rejects it because the string exceeds the maximum allowed path length (ENAMETOOLONG), causing an unhandled crash that kills the session entirely. Gracefully handle the compiler error without crashing, or The session should not terminate. At minimum, the error should be caught and surfaced as a warning rather than an unhandled promise rejection.

Root Cause

When a Next.js compiler error exists in the dev environment (e.g., a missing default export), Gemini CLI crashes with an unhandled promise rejection: CRITICAL: Unhandled Promise Rejection! Error: ENAMETOOLONG: name too long, lstat '/lib/utils"; 9 | import BrandSwitcher from "@/components/shared/BrandSwitcher";

10 | import ThemeToggle from "@/components/shared/ThemeToggle"; ... The CLI appears to be passing the raw Next.js compiler error message string (which includes multi-line code snippets) directly into lstat() as a file path via robustRealpath() → resolveToRealPath() → checkPermissions(). The OS rejects it because the string exceeds the maximum allowed path length (ENAMETOOLONG), causing an unhandled crash that kills the session entirely. Relevant stack trace: at Module.lstatSync (node:fs:1686:25) at robustRealpath (chunk-JS5WSGB2.js:41541:27) at resolveToRealPath (chunk-JS5WSGB2.js:41528:10) at checkPermissions (chunk-XDYYZLVW.js:74042:30)

RAW_BUFFERClick to expand / collapse

What happened?

[ACTION REQUIRED] 📎 PLEASE ATTACH THE EXPORTED CHAT HISTORY JSON FILE TO THIS ISSUE IF YOU FEEL COMFORTABLE SHARING IT.

When a Next.js compiler error exists in the dev environment (e.g., a missing default export), Gemini CLI crashes with an unhandled promise rejection: CRITICAL: Unhandled Promise Rejection! Error: ENAMETOOLONG: name too long, lstat '/lib/utils"; 9 | import BrandSwitcher from "@/components/shared/BrandSwitcher";

10 | import ThemeToggle from "@/components/shared/ThemeToggle"; ... The CLI appears to be passing the raw Next.js compiler error message string (which includes multi-line code snippets) directly into lstat() as a file path via robustRealpath() → resolveToRealPath() → checkPermissions(). The OS rejects it because the string exceeds the maximum allowed path length (ENAMETOOLONG), causing an unhandled crash that kills the session entirely. Relevant stack trace: at Module.lstatSync (node:fs:1686:25) at robustRealpath (chunk-JS5WSGB2.js:41541:27) at resolveToRealPath (chunk-JS5WSGB2.js:41528:10) at checkPermissions (chunk-XDYYZLVW.js:74042:30)

What did you expect to happen?

Gemini CLI should either:

Gracefully handle the compiler error without crashing, or Validate that a string is a plausible file path before passing it to lstat() / robustRealpath()

The session should not terminate. At minimum, the error should be caught and surfaced as a warning rather than an unhandled promise rejection.

Client information

  • CLI Version: 0.37.2
  • Git Commit: 545e956c3
  • Session ID: 929e68fb-db38-40bd-a3de-0ca8aea74fb9
  • Operating System: darwin v25.9.0
  • Sandbox Environment: no sandbox
  • Model Version: auto-gemini-3
  • Auth Type: oauth-personal
  • Memory Usage: 323.7 MB
  • Terminal Name: Unknown
  • Terminal Background: #212734
  • Kitty Keyboard Protocol: Unsupported

Login information

No response

Anything else we need to know?

No response

extent analysis

TL;DR

The Gemini CLI crashes due to an unhandled promise rejection when a Next.js compiler error occurs, caused by passing a long error message string as a file path to lstat(), exceeding the maximum allowed path length.

Guidance

  • Validate the input to lstat() and robustRealpath() to ensure it's a plausible file path before passing it, to prevent the ENAMETOOLONG error.
  • Consider catching and handling the error in checkPermissions() to prevent the unhandled promise rejection and provide a more informative error message instead of crashing.
  • Review the resolveToRealPath() function to determine why it's passing the raw Next.js compiler error message as a file path, and modify it to handle such cases correctly.
  • To mitigate the issue, you can try to reduce the length of the error message or modify the lstat() call to handle longer paths.

Example

No code snippet is provided as the issue does not contain sufficient information to create a specific example.

Notes

The root cause of the issue seems to be the incorrect handling of the Next.js compiler error message as a file path. The solution will depend on the specific implementation of the robustRealpath() and resolveToRealPath() functions, which are not provided in the issue.

Recommendation

Apply a workaround to validate the input to lstat() and robustRealpath() to prevent the ENAMETOOLONG error, as the root cause of the issue is not directly related to a specific version that can be upgraded.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING