react-native-testing-library
react-native-testing-library copied to clipboard
Cannot install the library with React 19.0.0
I'm trying to use this library with React 19.0.0 but when I run npm install --save-dev @testing-library/react-native it gives me this error:
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: [email protected]
npm error Found: [email protected]
npm error node_modules/react
npm error react@"19.0.0" from the root project
npm error peer react@">=18.2.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react-native
npm error dev @testing-library/react-native@"13.2.0" from the root project
npm error 1 more (react-native)
npm error
npm error Could not resolve dependency:
npm error peer react@"^19.1.0" from [email protected]
npm error node_modules/react-test-renderer
npm error peer react-test-renderer@">=18.2.0" from @testing-library/[email protected]
npm error node_modules/@testing-library/react-native
npm error dev @testing-library/react-native@"13.2.0" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.
npm error
npm error
npm error For a full report see:
npm error /Users/christianpredebon/.npm/_logs/2025-05-20T16_32_23_577Z-eresolve-report.txt
npm error A complete log of this run can be found in: /Users/christianpredebon/.npm/_logs/2025-05-20T16_32_23_577Z-debug-0.log
Also, if I install React 19.1.0 and then run the tests it says Incorrect version of "react-test-renderer" detected. Expected "19.1.0", but found "19.0.0".
Steps to Reproduce
- create a project with Expo
53.0.9and React19.0.0 - run cmd
npm install --save-dev @testing-library/react-native
Versions
npmPackages:
react: 19.0.0 => 19.0.0
react-native: 0.79.2 => 0.79.2
Same here, new project with latest Expo.
I'm on React Native 0.78 and was able to successfully install with React 19.0.0.
However, when I tried React 19.1.0, some of my tests - specifically, ones that tested components which use react-native-reanimated or react-native-gesture-handler would fail with the a similar message to what the OP mentions:
Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:
- react: 19.1.0
- react-native-renderer: 19.0.0
Learn more: https://react.dev/warnings/version-mismatch
Weirdly, there seems to be no react-native-renderer package (npm ls react-native-renderer doesn't find anything, and searching for it on npmjs.com shows that it's latest version was 15.5.3, so there is no 19.0.0).
However, assuming the error message is mistyped, and they might have meant react-_test_-renderer, then the version mentioned in the error message is incorrect. Both react and react-test-renderer are on the same 19.1.0 version in my env. Here's the relevant output from npm ls that confirms this:
[email protected]
βββ¬ [email protected] -> ./packages/my-package
...
β βββ¬ [email protected] overridden
β β βββ [email protected] deduped
β βββ [email protected] overridden
...
When I downgraded both to 19.0.0, everything worked fine.
Same issue.
npmPackages: react: 19.0.0 react-native: 0.79.2
i tried to update react and react-dom to 19.1.0 but then i get the error that James mentioned on the comment above:
Warning: Error: Incompatible React versions: The "react" and "react-native-renderer" packages must have the exact same version. Instead got:
- react: 19.1.0
- react-native-renderer: 19.0.0
Learn more: https://react.dev/warnings/version-mismatch, js engine: hermes
Use [email protected] instead of react-native-renderer (RNTL is reporting wrong name).
Where do you install react-native-renderer from though?
On npmjs.com, the most recent version is 15.5.3 (from 8 years ago (!)): https://www.npmjs.com/package/react-native-renderer
Did someone forget to npm publish perhaps?
Hi @mdjastrzebski
Not clear for me as well.
So I created a repository that replicates the issue, of a blank expo project , maybe easier to show/explain the issue. https://github.com/FabioMadeiraPt/react-test-example
If I try to add 'npx expo install @testing-library/react-native --dev' it returns the error that was reported.
@FabioMadeiraPt thanks for the repo.
Make sure you have:
"devDependencies": {
// ...
"react-test-renderer": "19.0.0",
// ...
},
in your package.json.
Watch out not to use ^19.0.0 (with ^) as it might want to install 19.1.0 which will trigger the NPM error posted by OP.
Thanks for the quick replies. I can confirm that fixed the issue for me. Everything works fine on 19.0.0
Thanks, I can also confirm that adding react-test-renderer to the dev dependencies works
Hey guys the fix works for me too. I recommend follow the next steps:
- Add manually the dependency "react-test-renderer": "19.0.0"
- Install react testing library with the command:
npx expo install @testing-library/react-native --dev
- enjoy
Sounds a bit crazy that the testing library requires a higher React version than what React Native supports π Anyway, @mdjastrzebskiβs solution worked perfectly for me too. Thanks!
Closing as solved.
@mdjastrzebski Is this really resolved? Hardcoding the package to "19.0.0" isn't a great fix - people are going to forget to update their pacakage.json and 5 years from now projects are going to be on this (then ancient) version.
@dmathisen what else can we realistically do?
react-test-renderer version needs to match versions of user's react package. But it's the user controlling his react and react-test-renderer versions, not RNTL.
NPM could have a smarter peer deps resultion algo, or do not install them (like yarn works).
react-test-rendererversion needs to match versions of user'sreactpackage
Got it. Yeah, I see the issue. I guess that's all you can do. Thanks for the explanation.
@FabioMadeiraPt thanks for the repo.
Make sure you have:
"devDependencies": { // ... "react-test-renderer": "19.0.0", // ... },in your package.json.
Watch out not to use
^19.0.0(with^) as it might want to install19.1.0which will trigger the NPM error posted by OP.
I can confirmed that this works on expo SDK-54 as well. But with version 19.1.0
"react-test-renderer": "19.1.0"