Next.js Discord

Discord Forum

Next.JS with vitest: React.cache is not defined

Unanswered
Bull Arab posted this in #help-forum
Open in Discord
Bull ArabOP
If you are using React.cache in your component and try to use vitest, you'll get hit with

FAIL cache/index.test.ts [ cache/index.test.ts ]
TypeError: Rect.cache is not a function
❯ cache/index.ts:9:50

This makes sense because the vitejs react plugin does not support React.cache, although next.js' node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js does.

What's the best way to use Next.JS with Vitest?

0 Replies