jest-community / eslint-plugin-jest

ESLint plugin for Jest
MIT License
1.12k stars 228 forks source link

Conflicting Peer Dependency Between eslint-plugin-jest and typescript-eslint #1613

Closed CHC383 closed 3 weeks ago

CHC383 commented 3 weeks ago

Hi, when I tried to upgrade eslint-plugin-jest from 28.5.0 to 28.6.0, I got the following NPM conflict error which I couldn't understand. It complains about @typescript-eslint/parser, but eslint-plugin-jest doesn't depends on it, instead it has @typescript-eslint/eslint-plugin@"^6.0.0 || ^7.0.0 as peerOptional which aligns with @typescript-eslint/eslint-plugin@7.13.0 in the project (coming from typescript-eslint@7.13.0).

I guess the error message might be misleading and there are some other dependency problems. Any pointers would be appreciated.

npm error While resolving: root-project@x.x.x
npm error Found: eslint-plugin-jest@28.5.0
npm error node_modules/eslint-plugin-jest
npm error   dev eslint-plugin-jest@"28.6.0" from the root project
npm error
npm error Could not resolve dependency:
npm error dev eslint-plugin-jest@"28.6.0" from the root project
npm error
npm error Conflicting peer dependency: @typescript-eslint/parser@7.13.0
npm error node_modules/@typescript-eslint/parser
npm error   peer @typescript-eslint/parser@"^7.0.0" from @typescript-eslint/eslint-plugin@7.13.0
npm error   node_modules/@typescript-eslint/eslint-plugin
npm error     peerOptional @typescript-eslint/eslint-plugin@"^6.0.0 || ^7.0.0" from eslint-plugin-jest@28.6.0
npm error     node_modules/eslint-plugin-jest
npm error       dev eslint-plugin-jest@"28.6.0" from the root project
G-Rath commented 3 weeks ago

Yeah NPM's peer dependency messages can be confusing - first thing I'd try is changing the order around and also uninstall things completely; I'd start with uninstalling eslint-plugin-jest completely then re-adding it, then removing all three dependencies and re-adding them together, and a few variations of that.

I've found one of the core problems is the order of things - if you've already got something as a dependency, npm seems to focus on trying to make things work with the existing constraints even if they're optional, whereas when a dependency is being added fresh it seems to take a slightly different approach

CHC383 commented 3 weeks ago

Thanks @G-Rath , turns out that it is due some weird status among eslint-plugin-jest, eslint-config-next and typescript-eslint, the node_modules/@typescript-eslint/parser in package-lock.json was 6.21.0, after removing and re-adding them, it is now 7.13.0 and everything works fine.

Removing eslint-plugin-jest first did help as NPM gave me a different conflicting message that led me to eslint-config-next. And the whole issue might be caused by some force installation (--force) before, and likely to be the dependency resolution differences you mentioned above.