Is there a way to solve: While resolving: image-jest@1.0.0 npm ERR! Found: react@17.0.1

I am trying to install @testing-library/react-native to a freshly created expo-based react native application.

For adding test cases, I followed the steps mentioned in Testing with Jest - Expo Documentation and installed jest and jest-expo

After that, I tried installing @testing-library/react-native using the command

npm install --save-dev @testing-library/react-native

and started getting the below error

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: image-jest@1.0.0
npm ERR! Found: react@17.0.1
npm ERR! node_modules/react
npm ERR!   react@"17.0.1" from the root project
npm ERR!   peer react@">=16.0.0" from @testing-library/react-native@9.0.0
npm ERR!   node_modules/@testing-library/react-native
npm ERR!     dev @testing-library/react-native@"*" from the root project
npm ERR!   1 more (react-native)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.2" from react-test-renderer@17.0.2
npm ERR! node_modules/react-test-renderer
npm ERR!   peer react-test-renderer@">=16.0.0" from @testing-library/react-native@9.0.0
npm ERR!   node_modules/@testing-library/react-native
npm ERR!     dev @testing-library/react-native@"*" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

My package.json looks like below

{
  "name": "image-jest",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web",
    "eject": "expo eject",
    "test": "jest"
  },
  "dependencies": {
    "expo": "~44.0.0",
    "expo-status-bar": "~1.2.0",
    "react": "17.0.1",
    "react-dom": "17.0.1",
    "react-native": "0.64.3",
    "react-native-web": "0.17.1"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/jest": "^27.4.1",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.64.12",
    "jest": "^26.6.3",
    "jest-expo": "^44.0.1",
    "typescript": "~4.3.5"
  },
  "jest": {
    "preset": "jest-expo",
    "transformIgnorePatterns": [
      "node_modules/(?!((jest-)?react-native|@react-native(-community)?)|expo(nent)?|@expo(nent)?/.*|@expo-google-fonts/.*|react-navigation|@react-navigation/.*|@unimodules/.*|unimodules|sentry-expo|native-base|react-native-svg)"
    ]
  },
  "private": true
}

I am unable to understand what is causing the issue. Can anyone suggest what can be done to fix it?

Same question posted over stackoverflow: testing - React native jest: While resolving: image-jest@1.0.0 npm ERR! Found: react@17.0.1 - Stack Overflow

Hi @sumit.surana

Try:

npm install --save-dev --legacy-peer-deps @testing-library/react-native

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.