nextjs - ✅(Solved) Fix `<Image>` cache issue with long domain names `ENAMETOOLONG: name too long, open` [1 pull requests, 1 participants]

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…
GitHub stats
vercel/next.js#85978Fetched 2026-04-08 02:13:11
View on GitHub
Comments
0
Participants
1
Timeline
6
Reactions
1
Participants
Timeline (top)
subscribed ×2cross-referenced ×1issue_type_added ×1labeled ×1

Error Message

GET / 200 in 13ms (compile: 1664µs, render: 12ms) ⨯ Failed to write image to cache BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4 Error: ENAMETOOLONG: name too long, open '/Users/michael/Documents/random/enametoolong/.next/dev/cache/images/BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4/2592000.1765392523271.ezh_j_tR2DQKWH-guVFbjeWNxFJtxneBgE3yp-rI7SA.NmNiMzg2YmZiM2NkMTQ5YjMwNmY4NTQwZWFmZDk4ZTY4N2IzNDAxYzE3NjI1MTUzNzMzOTk0X3plM2NlZmRiY2FmYmU4MWY5OGVhNDA1MWVfZjExODc1ZWE2NGYwZTA2MmJfZDIwMjUxMTA3X20xMTM2MTNfYzAwM192MDMxMjAzMF90MDAxNF91MDE3NjI1MTUzNzM1MjU.webp' at ignore-listed frames { errno: -63, code: 'ENAMETOOLONG', syscall: 'open', path: '/Users/michael/Documents/random/enametoolong/.next/dev/cache/images/BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4/2592000.1765392523271.ezh_j_tR2DQKWH-guVFbjeWNxFJtxneBgE3yp-rI7SA.NmNiMzg2YmZiM2NkMTQ5YjMwNmY4NTQwZWFmZDk4ZTY4N2IzNDAxYzE3NjI1MTUzNzMzOTk0X3plM2NlZmRiY2FmYmU4MWY5OGVhNDA1MWVfZjExODc1ZWE2NGYwZTA2MmJfZDIwMjUxMTA3X20xMTM2MTNfYzAwM192MDMxMjAzMF90MDAxNF91MDE3NjI1MTUzNzM1MjU.webp' }

Fix Action

Fixed

PR fix notes

PR #86102: fix: ENAMETOOLONG error by ETag handling in image optimizer #85978

Description (problem / solution / changelog)

Replaced the base64url encoding of the upstream ETag with getHash function to create a short, filesystem-safe identifier.

What & Why?

If the upstream server sends a very long ETag, the encoded string becomes very long. The full file path exceeded the OS filename length limit (~255 characters). Then Node throws, ENAMETOOLONG.

How?

changed upstream ETag processing from: Buffer.from(etag).toString('base64url') to, getHash([etag]). This transforms, the ETag string into one fixed-size SHA-256 hash.

Fixes #85978

Changed files

  • packages/next/src/server/image-optimizer.ts (modified, +4/-3)

Code Example

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:26 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6041
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 24.11.0
  npm: 11.6.1
  Yarn: N/A
  pnpm: 10.11.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

---

GET / 200 in 13ms (compile: 1664µs, render: 12ms)
Failed to write image to cache BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4 Error: ENAMETOOLONG: name too long, open '/Users/michael/Documents/random/enametoolong/.next/dev/cache/images/BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4/2592000.1765392523271.ezh_j_tR2DQKWH-guVFbjeWNxFJtxneBgE3yp-rI7SA.NmNiMzg2YmZiM2NkMTQ5YjMwNmY4NTQwZWFmZDk4ZTY4N2IzNDAxYzE3NjI1MTUzNzMzOTk0X3plM2NlZmRiY2FmYmU4MWY5OGVhNDA1MWVfZjExODc1ZWE2NGYwZTA2MmJfZDIwMjUxMTA3X20xMTM2MTNfYzAwM192MDMxMjAzMF90MDAxNF91MDE3NjI1MTUzNzM1MjU.webp'
    at ignore-listed frames {
  errno: -63,
  code: 'ENAMETOOLONG',
  syscall: 'open',
  path: '/Users/michael/Documents/random/enametoolong/.next/dev/cache/images/BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4/2592000.1765392523271.ezh_j_tR2DQKWH-guVFbjeWNxFJtxneBgE3yp-rI7SA.NmNiMzg2YmZiM2NkMTQ5YjMwNmY4NTQwZWFmZDk4ZTY4N2IzNDAxYzE3NjI1MTUzNzMzOTk0X3plM2NlZmRiY2FmYmU4MWY5OGVhNDA1MWVfZjExODc1ZWE2NGYwZTA2MmJfZDIwMjUxMTA3X20xMTM2MTNfYzAwM192MDMxMjAzMF90MDAxNF91MDE3NjI1MTUzNzM1MjU.webp'
}
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/MichaelHillcox/nextjs-16-enametoolong

To Reproduce

  1. Create a repo using the npm create command
  2. Add an <Image> tag
  3. Add the CDN domain into the remotePatterns
  4. Set the src of the image to a relatively long domain https://cdn.feed-the-beast.com/assets/website/banners/sb4_merch.webp for example
  5. npm run dev
  6. See error

Current vs. Expected behavior

Current: Image displays but error logged in dev and deployed versions of the website. Expected: No error

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:26 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6041
  Available memory (MB): 65536
  Available CPU cores: 16
Binaries:
  Node: 24.11.0
  npm: 11.6.1
  Yarn: N/A
  pnpm: 10.11.0
Relevant Packages:
  next: 16.0.1 // Latest available version is detected (16.0.1).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Image (next/image)

Which stage(s) are affected? (Select all that apply)

Other (Deployed)

Additional context

Observe error given below.

 GET / 200 in 13ms (compile: 1664µs, render: 12ms)
 ⨯ Failed to write image to cache BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4 Error: ENAMETOOLONG: name too long, open '/Users/michael/Documents/random/enametoolong/.next/dev/cache/images/BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4/2592000.1765392523271.ezh_j_tR2DQKWH-guVFbjeWNxFJtxneBgE3yp-rI7SA.NmNiMzg2YmZiM2NkMTQ5YjMwNmY4NTQwZWFmZDk4ZTY4N2IzNDAxYzE3NjI1MTUzNzMzOTk0X3plM2NlZmRiY2FmYmU4MWY5OGVhNDA1MWVfZjExODc1ZWE2NGYwZTA2MmJfZDIwMjUxMTA3X20xMTM2MTNfYzAwM192MDMxMjAzMF90MDAxNF91MDE3NjI1MTUzNzM1MjU.webp'
    at ignore-listed frames {
  errno: -63,
  code: 'ENAMETOOLONG',
  syscall: 'open',
  path: '/Users/michael/Documents/random/enametoolong/.next/dev/cache/images/BLgPRtEFIVPcWJZFkpWkzy6FOgJL35rkPbXXJcyDSd4/2592000.1765392523271.ezh_j_tR2DQKWH-guVFbjeWNxFJtxneBgE3yp-rI7SA.NmNiMzg2YmZiM2NkMTQ5YjMwNmY4NTQwZWFmZDk4ZTY4N2IzNDAxYzE3NjI1MTUzNzMzOTk0X3plM2NlZmRiY2FmYmU4MWY5OGVhNDA1MWVfZjExODc1ZWE2NGYwZTA2MmJfZDIwMjUxMTA3X20xMTM2MTNfYzAwM192MDMxMjAzMF90MDAxNF91MDE3NjI1MTUzNzM1MjU.webp'
}

extent analysis

TL;DR

The error ENAMETOOLONG suggests that the file path for the cached image is too long, which can be resolved by shortening the cache directory path or modifying the caching mechanism.

Guidance

  • The issue seems to be related to the next/image component and the caching mechanism used by Next.js.
  • To mitigate this issue, consider shortening the domain name used in the src attribute of the Image tag or configure the caching directory to a shorter path.
  • Verify the fix by checking the console logs for the ENAMETOOLONG error after applying the changes.
  • If the issue persists, consider modifying the next.config.js file to customize the caching behavior.

Example

No specific code example can be provided without modifying the existing codebase, but consider using a shorter domain name or a different caching strategy.

Notes

This solution assumes that the issue is indeed related to the file path length and not a deeper problem with the caching mechanism or the next/image component.

Recommendation

Apply a workaround by shortening the cache directory path or modifying the caching mechanism, as upgrading to a fixed version is not implied in the given issue.

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