Sumit Surana
Sumit Surana

Reputation: 1584

React native jest: While resolving: [email protected] npm ERR! Found: [email protected]

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 https://docs.expo.dev/guides/testing-with-jest/ and installed jest and jest-expo.

After that, I tried installing @testing-library/react-native using 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: [email protected]
npm ERR! Found: [email protected]
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/[email protected]
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 [email protected]
npm ERR! node_modules/react-test-renderer
npm ERR!   peer react-test-renderer@">=16.0.0" from @testing-library/[email protected]
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?

Upvotes: 0

Views: 276

Answers (1)

iliana simon
iliana simon

Reputation: 11

The error is because the [email protected] requires [email protected], while you have an older version of react.

Try to install an older version of react-test-renderer first:

npm i [email protected]

And then install @testing-library/react-native

Upvotes: 1

Related Questions