You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Error: Objects are not valid as a React child ... #1387
Okay. I managed to fix this. Downgrading react doesn't work since react is now bundled with nextjs and it's using it's own internal react. So you can either try and point the react plugin for vitejs at the development version of react inside of nextjs, OR simply remove your project's dependencies on react and react-dom. The latter was much simpler for me.
@jay-linumlabs Have you found any workaround for this? I assume it is not a react-testing-library alone issue, React cannot be soo not backward incompatible. If my assumptions are correct, then what configuration are we doing wrong?
@jay-linumlabs Have you found any workaround for this? I assume it is not a react-testing-library alone issue, React cannot be soo not backward incompatible. If my assumptions are correct, then what configuration are we doing wrong?
I ended up not using vitest so I can move forward. I'm not sure if any recent changes or updates have resolved this issue. @bramski has a suggestion that could possibly work, but I have not tried it out.
Hello fellow vibe coders, I ran into this issue and got Claude to explain what went wrong in my case. Use the suggested workaround at your own peril, YMMV. This should work for those who want Next+React+Vitest in their stack.
Next.js 16 + React 19 + Vitest Testing Issue
The Problem: You trust that npm overrides work automatically. They don't—especially in monorepos with existing lock files.
What's Actually Wrong: React 18 gets installed alongside React 19 because your lock file persists old versions. Vitest then loads two React versions and breaks.
The Config Error to Expect:
# This reveals the problem:
npm list react
# You'll see:
react@18.3.1 invalid: "^19.2.0" ... overridden # ← Old version still there!
react@19.2.0 deduped # ← New version also there!
Why This Happens in Turborepo: Workspace hoisting means @testing-library/react lives at root, but React 19 is only installed in your app. Testing lib finds React 18 first.
The Fix:
# 1. Clean install to force overrides
rm -rf node_modules package-lock.json
npm install
# 2. Install React 19 at ROOT (critical for hoisted testing libs)
# Add to ROOT package.json:
{
"devDependencies": {
"react": "^19.2.0",
"react-dom": "^19.2.0"
}
}
# 3. Add Vite aliases in vitest.config.ts:
resolve: {
alias: {
'react': path.resolve(__dirname, '../../node_modules/react'),
'react-dom': path.resolve(__dirname, '../../node_modules/react-dom'),
'react/jsx-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-runtime.js'),
'react/jsx-dev-runtime': path.resolve(__dirname, '../../node_modules/react/jsx-dev-runtime.js'),
}
}
Verify: npm list react should show ONLY 19.x with "deduped" (no "invalid").
Activity
MatanBobi commentedon Mar 18, 2025
Can you please share a minimal reproduction for us to help?
bramski commentedon Jul 4, 2025
I'm also getting this... any updates to make this work?
bramski commentedon Jul 7, 2025
Okay. I managed to fix this. Downgrading react doesn't work since react is now bundled with nextjs and it's using it's own internal
react. So you can either try and point the react plugin for vitejs at the development version of react inside of nextjs, OR simply remove your project's dependencies onreactandreact-dom. The latter was much simpler for me.aralroca commentedon Oct 1, 2025
Any workaround to work with React 19 for this?
trdp30 commentedon Oct 4, 2025
@jay-linumlabs Have you found any workaround for this? I assume it is not a react-testing-library alone issue, React cannot be soo not backward incompatible. If my assumptions are correct, then what configuration are we doing wrong?
jay-linumlabs commentedon Oct 6, 2025
I ended up not using vitest so I can move forward. I'm not sure if any recent changes or updates have resolved this issue. @bramski has a suggestion that could possibly work, but I have not tried it out.
johnhkchen commentedon Nov 14, 2025
Hello fellow vibe coders, I ran into this issue and got Claude to explain what went wrong in my case. Use the suggested workaround at your own peril, YMMV. This should work for those who want Next+React+Vitest in their stack.