react-native-testing-library icon indicating copy to clipboard operation
react-native-testing-library copied to clipboard

Cannot install the library with React 19.0.0

Open christian-predebon opened this issue 6 months ago β€’ 11 comments
trafficstars

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.9 and React 19.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 

christian-predebon avatar May 20 '25 16:05 christian-predebon

Same here, new project with latest Expo.

qwerty2k avatar May 20 '25 19:05 qwerty2k

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.

james-nash avatar May 21 '25 00:05 james-nash

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

FabioMadeiraPt avatar May 21 '25 11:05 FabioMadeiraPt

Use [email protected] instead of react-native-renderer (RNTL is reporting wrong name).

mdjastrzebski avatar May 21 '25 14:05 mdjastrzebski

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?

james-nash avatar May 21 '25 15:05 james-nash

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 avatar May 21 '25 15:05 FabioMadeiraPt

@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.

mdjastrzebski avatar May 21 '25 15:05 mdjastrzebski

Thanks for the quick replies. I can confirm that fixed the issue for me. Everything works fine on 19.0.0

FabioMadeiraPt avatar May 21 '25 16:05 FabioMadeiraPt

Thanks, I can also confirm that adding react-test-renderer to the dev dependencies works

christian-predebon avatar May 21 '25 19:05 christian-predebon

Hey guys the fix works for me too. I recommend follow the next steps:

  1. Add manually the dependency "react-test-renderer": "19.0.0"
  2. Install react testing library with the command:
npx expo install @testing-library/react-native --dev
  1. enjoy

ronaldrequena avatar Jun 07 '25 16:06 ronaldrequena

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!

Alex100dre avatar Jun 11 '25 13:06 Alex100dre

Closing as solved.

mdjastrzebski avatar Jul 14 '25 13:07 mdjastrzebski

@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 avatar Sep 14 '25 18:09 dmathisen

@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).

mdjastrzebski avatar Sep 14 '25 20:09 mdjastrzebski

react-test-renderer version needs to match versions of user's react package

Got it. Yeah, I see the issue. I guess that's all you can do. Thanks for the explanation.

dmathisen avatar Sep 22 '25 17:09 dmathisen

@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.

I can confirmed that this works on expo SDK-54 as well. But with version 19.1.0

"react-test-renderer": "19.1.0"

yourjhay avatar Oct 20 '25 12:10 yourjhay