nextjs - 💡(How to fix) Fix Importing/running cached functions in proxy.ts [2 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

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#85475Fetched 2026-04-08 02:15:29
View on GitHub
Comments
2
Participants
3
Timeline
12
Reactions
8
Timeline (top)
subscribed ×6labeled ×3commented ×2issue_type_added ×1

Error Message

Currently, I get the following error in the terminal and as a popup when running next dev: cacheLife is in fact being called inside a "use cache" function and it works as expected if I use the function in any other place than proxy.ts. The error message implies that the issue is that the function doesn't have "use cache", but it seems to have more to do with the usage inside of proxy.ts.

Code Example

`cacheLife()` can only be called inside a "use cache" function.

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.5.1
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 16.0.0 // Latest available version is detected (16.0.0).
  eslint-config-next: N/A
  react: 19.2.0
  react-dom: 19.2.0
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/empty-glade-srklzq

To Reproduce

  1. Start the application in dev mode (next dev)
  2. Open the browser and navigate to the application (usually http://localhost:3000)
  3. Errors will appear in both the console and on screen

Current vs. Expected behavior

I expect the cached function to run in the proxy.ts. In my actual code (looks very similar), I'm doing a cheap API call, cached as "weeks", in order to load some configurations for a multi-tenant application. This basic multi-tenant configuration is hosted externally and is rarely changes, so it shouldn't be fetched for every new visitor of the application, and definitely not for every new request. However, the result is needed in order to start loading the page.

Currently, I get the following error in the terminal and as a popup when running next dev:

`cacheLife()` can only be called inside a "use cache" function.
<img width="956" height="754" alt="Image" src="https://github.com/user-attachments/assets/ebf6152a-ef89-4db8-801e-2b707d03da85" />

cacheLife is in fact being called inside a "use cache" function and it works as expected if I use the function in any other place than proxy.ts. The error message implies that the issue is that the function doesn't have "use cache", but it seems to have more to do with the usage inside of proxy.ts.

Is this intended but undocumented behavior, a bug, or am I missing something?

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.0.0: Wed Sep 17 21:41:45 PDT 2025; root:xnu-12377.1.9~141/RELEASE_ARM64_T6000
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 22.5.1
  npm: 10.8.2
  Yarn: 1.22.22
  pnpm: N/A
Relevant Packages:
  next: 16.0.0 // Latest available version is detected (16.0.0).
  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)

Use Cache, Runtime, Middleware

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

next dev (local)

Additional context

No response

extent analysis

TL;DR

The issue is likely due to the cacheLife function being called outside of a valid React context in proxy.ts, and a workaround may involve reorganizing the code to ensure cacheLife is called within a React component or a custom hook.

Guidance

  • Verify that cacheLife is indeed being called within a "use cache" function in proxy.ts by checking the code and any potential higher-order functions or wrappers.
  • Consider reorganizing the code to ensure cacheLife is called within a React component or a custom hook, as the error message suggests it requires a specific context.
  • Investigate if there are any specific restrictions or limitations on using cacheLife within proxy.ts or Next.js middleware.
  • Check the Next.js documentation and any related issues on GitHub to see if this is a known limitation or bug.

Example

No code example is provided as the issue is more related to the context and usage of cacheLife rather than a specific code snippet.

Notes

The issue seems to be specific to the next dev stage and proxy.ts file, and may not be a general problem with the cacheLife function. Further investigation is needed to determine the root cause and a suitable solution.

Recommendation

Apply workaround: Reorganize the code to ensure cacheLife is called within a valid React context, as this is the most likely solution based on the error message and the context of the 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