enzymejs / enzyme

JavaScript Testing utilities for React
https://enzymejs.github.io/enzyme/
MIT License
19.95k stars 2.01k forks source link

Failure installing enzyme-adapter-react-16 with react 16.13.1 #2513

Open TommyLeong opened 3 years ago

TommyLeong commented 3 years ago

Current behavior

Tried to install enzyme-adapter-react-16 with React-Native Version 0.63.2 and React 16.13.1

Installation command npm i --save-dev enzyme-adapter-react-16

Error received

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: myapp@0.0.1
npm ERR! Found: react@16.13.1
npm ERR! node_modules/react
npm ERR!   react@"16.13.1" from the root project
npm ERR!   peer react@"^16.0.0-0" from enzyme-adapter-react-16@1.15.6
npm ERR!   node_modules/enzyme-adapter-react-16
npm ERR!     dev enzyme-adapter-react-16@"*" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.14.0" from react-dom@16.14.0
npm ERR! node_modules/react-dom
npm ERR!   react-dom@"^16.13.1" from the root project
npm ERR!   peer react-dom@"^16.0.0-0" from enzyme-adapter-react-16@1.15.6
npm ERR!   node_modules/enzyme-adapter-react-16
npm ERR!     dev enzyme-adapter-react-16@"*" 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.

Expected behavior

To install successfully

Your environment

Package.json

"react": "16.13.1",
"react-dom": "^16.13.1",
"react-native": "0.63.2",
"enzyme": "^3.11.0",
"react-test-renderer": "16.13.1"

Machine

Node -v `15.11.0`
NPM -v `7.6.1`

Adapter

ljharb commented 3 years ago

Your lockfile seems to suggest it’s installing react-dom 16.14 somewhere, which would require react 16.14.

You can either update both react and react-dom to 16.14, or you can downgrade react-dom to 16.13. Try installing react, react-dom, and the enzyme adapter all in the same install command.

TommyLeong commented 3 years ago

@ljharb your suggestion helps to install enzyme-adapter-react-16 successfully.. but I realized after removing the file package-lock.json and again try to reinstall via npm install

At the same time, if I try to install other package (eg, npm i react-native-config) I get other issue as follow

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: myapp@0.0.1
npm ERR! Found: react@16.14.0
npm ERR! node_modules/react
npm ERR!   react@"16.14.0" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer react@"17.0.1" from react-native-windows@0.64.3
npm ERR! node_modules/react-native-windows
npm ERR!   peer react-native-windows@">=0.61" from react-native-config@1.4.2
npm ERR!   node_modules/react-native-config
npm ERR!     react-native-config@"*" 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.

In short, switching react and react-dom to version 16.14.0 resolved my installation but raise other issues.

ljharb commented 3 years ago

That means that version of react-native-windows requires react 17, which means it's incompatible with react 16 and can't be used. You'll either have to remove it, or downgrade it to one that supports react 16.