Next.js Discord

Discord Forum

Running into issue with `cache` from React.

Answered
Giant ichneumon wasp posted this in #help-forum
Open in Discord
Giant ichneumon waspOP
When I'm trying to use cache, I'm getting this error (pnpm monorepo if relevant)
 ⨯ (0 , react__WEBPACK_IMPORTED_MODULE_0__.cache) is not a function
Answered by Giant ichneumon wasp
This is actually solved by having cache run not at a module level. Basically what was going on was
import { headers } from '...';
export const a = headers().get('a');
when what should've been happening was
import { headers } from '...';
export const a = () => headers().get('a');
. The error is really unintuitive though, and should probably be looked at being improved.
View full answer

1 Reply

Giant ichneumon waspOP
This is actually solved by having cache run not at a module level. Basically what was going on was
import { headers } from '...';
export const a = headers().get('a');
when what should've been happening was
import { headers } from '...';
export const a = () => headers().get('a');
. The error is really unintuitive though, and should probably be looked at being improved.
Answer