create-react-app icon indicating copy to clipboard operation
create-react-app copied to clipboard

How to resolve conflicting dependencies

Open roberthchapman opened this issue 7 years ago • 9 comments

Hi, I have an issue on build when I install react-aad-msal where the build script complains about conflicting versions of "babel-jest". Running "npm ls babel-jest" gives the following:

Library: Dependency: [email protected] | +-- [email protected] [email protected] `-- [email protected]

The suggested solution is to remove the babel-jest dependency from package.json but there's no such thing in my package.json, it simply comes embedded as a dependency in the react-aad-msal library. Note I am using yarn not npm so don't have switching to yarn as a possible solution.

So my next step was to try downloading the CRA sample project and adding react-aad-msal to it. This showed exactly the same dependency conflict when you run "npm ls babel-jest" BUT it then proceeds to build without any error! So my question is why does the build script complain in one situation but not in the other? And what sort of thing should I be trying next?

The full error on build is below....thanks

yarn run v1.12.1 $ set REACT_APP_ENV=dev&&react-scripts start There might be a problem with the project dependency tree. It is likely not a bug in Create React App, but something you need to fix locally. The react-scripts package provided by Create React App requires a dependency: "babel-jest": "23.6.0" Don't try to install it manually: your package manager does it automatically. However, a different version of babel-jest was detected higher up in the tree: ......\node_modules\babel-jest (version: 22.4.4) Manually installing incompatible versions is known to cause hard-to-debug issues. If you would prefer to ignore this check, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That will permanently disable this message but you might encounter other issues.

To fix the dependency tree, try following the steps below in the exact order:

  1. Delete package-lock.json (not package.json!) and/or yarn.lock in your project folder.
  2. Delete node_modules in your project folder.
  3. Remove "babel-jest" from dependencies and/or devDependencies in the package.json file in your project folder.
  4. Run npm install or yarn, depending on the package manager you use. In most cases, this should be enough to fix the problem. If this has not helped, there are a few other things you can try:
  5. If you used npm, install yarn (http://yarnpkg.com/) and repeat the above steps with it instead. This may help because npm has known issues with package hoisting which may get resolved in future versions.
  6. Check if C:\ecp\ecpwebapplications\ecpexternal\node_modules\babel-jest is outside your project directory. For example, you might have accidentally installed something in your home folder.
  7. Try running npm ls babel-jest in your project folder. This will tell you which other package (apart from the expected react-scripts) installed babel-jest.

If nothing else helps, add SKIP_PREFLIGHT_CHECK=true to an .env file in your project. That would permanently disable this preflight check in case you want to proceed anyway.

P.S. We know this message is long but please read the steps above :-) We hope you find them helpful!

roberthchapman avatar Jan 30 '19 12:01 roberthchapman

Hi @roberthchapman, this is a little strange. Have you tried using yarn to see if the results are different?

mrmckeb avatar Jan 30 '19 14:01 mrmckeb

Hi @mrmckeb I'm not sure I follow exactly - I said above "Note I am using yarn not npm so don't have switching to yarn as a possible solution."

The confusion might be that I said I tried "npm ls babel-jest" - that's simply because that's the only command I had to find dependencies in common. I don't know enough about yarn fundamentals to know if running that is a problem but I've just spent some time on the yarn web site and can't seem to find any equivalent. I used yarn on both my project and on the CRA sample project with that library added.

I've been looking in the yarn.lock files so thought it might be helpful to see what entries they have in the non-working project (mine) and the working project (CRA sample app). That's all below but I can now summarise it - they're exactly the same except the non-working version has entries for [email protected] with babel-jest "23.6.0", which has to be what will be causing the problem in this one and not the other. So any ideas what I should do, given that?

Non-working: [email protected], babel-jest@^23.6.0: version "23.6.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-23.6.0.tgz#a644232366557a2240a0c083da6b25786185a2f1" dependencies: babel-plugin-istanbul "^4.1.6" babel-preset-jest "^23.2.0"

Working: [email protected], babel-jest@^23.6.0: version "23.6.0" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-23.6.0.tgz#a644232366557a2240a0c083da6b25786185a2f1" integrity sha512-lqKGG6LYXYu+DQh/slrQ8nxXQkEkhugdXsU6St7GmhVS7Ilc/22ArwqXNJrf0QaOBjZB0360qZMwXqDYQHXaew== dependencies: babel-plugin-istanbul "^4.1.6" babel-preset-jest "^23.2.0"

Non-working: babel-jest@^22.1.0, babel-jest@^22.4.4: version "22.4.4" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-22.4.4.tgz#977259240420e227444ebe49e226a61e49ea659d" integrity sha512-A9NB6/lZhYyypR9ATryOSDcqBaqNdzq4U+CN+/wcMsLcmKkPxQEoTKLajGfd3IkxNyVBT8NewUK2nWyGbSzHEQ== dependencies: babel-plugin-istanbul "^4.1.5" babel-preset-jest "^22.4.4"

Working: babel-jest@^22.1.0, babel-jest@^22.4.4: version "22.4.4" resolved "https://registry.yarnpkg.com/babel-jest/-/babel-jest-22.4.4.tgz#977259240420e227444ebe49e226a61e49ea659d" integrity sha512-A9NB6/lZhYyypR9ATryOSDcqBaqNdzq4U+CN+/wcMsLcmKkPxQEoTKLajGfd3IkxNyVBT8NewUK2nWyGbSzHEQ== dependencies: babel-plugin-istanbul "^4.1.5" babel-preset-jest "^22.4.4"

Non-working: jest-config@^23.6.0: version "23.6.0" resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.6.0.tgz#f82546a90ade2d8c7026fbf6ac5207fc22f8eb1d" dependencies: babel-core "^6.0.0" babel-jest "^23.6.0"

Working: jest-config@^23.6.0: version "23.6.0" resolved "https://registry.yarnpkg.com/jest-config/-/jest-config-23.6.0.tgz#f82546a90ade2d8c7026fbf6ac5207fc22f8eb1d" integrity sha512-i8V7z9BeDXab1+VNo78WM0AtWpBRXJLnkT+lyT+Slx/cbP5sZJ0+NDuLcmBE5hXAoK0aUp7vI+MOxR+R4d8SRQ== dependencies: babel-core "^6.0.0" babel-jest "^23.6.0"

Non-working: jest-runtime@^22.4.4: version "22.4.4" resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-22.4.4.tgz#9ba7792fc75582a5be0f79af6f8fe8adea314048" integrity sha512-WRTj9m///npte1YjuphCYX7GRY/c2YvJImU9t7qOwFcqHr4YMzmX6evP/3Sehz5DKW2Vi8ONYPCFWe36JVXxfw== dependencies: babel-core "^6.0.0" babel-jest "^22.4.4"

Working: jest-runtime@^22.4.4: version "22.4.4" resolved "https://registry.yarnpkg.com/jest-runtime/-/jest-runtime-22.4.4.tgz#9ba7792fc75582a5be0f79af6f8fe8adea314048" integrity sha512-WRTj9m///npte1YjuphCYX7GRY/c2YvJImU9t7qOwFcqHr4YMzmX6evP/3Sehz5DKW2Vi8ONYPCFWe36JVXxfw== dependencies: babel-core "^6.0.0" babel-jest "^22.4.4"

Non-working: react-aad-msal@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/react-aad-msal/-/react-aad-msal-0.4.1.tgz#b178adc38166ad1e1ad85d71d51c61fdd4662fd1" integrity sha512-9lNogDTFEOPbNWvuzw3D/539q88fb71V16p7+93sE7bg3SZZOJf6buwe2nlKJnfv2+bb8f6CYGmEacXX5tBzeQ== dependencies: ... babel-jest "^22.1.0" ...

react-aad-msal@^0.4.1: version "0.4.1" resolved "https://registry.yarnpkg.com/react-aad-msal/-/react-aad-msal-0.4.1.tgz#b178adc38166ad1e1ad85d71d51c61fdd4662fd1" integrity sha512-9lNogDTFEOPbNWvuzw3D/539q88fb71V16p7+93sE7bg3SZZOJf6buwe2nlKJnfv2+bb8f6CYGmEacXX5tBzeQ== dependencies: .... babel-jest "^22.1.0"

Non-working: [email protected]: version "2.1.3" resolved "https://registry.yarnpkg.com/react-scripts/-/react-scripts-2.1.3.tgz#6e49be279f4039fb9f330d2b3529b933b8e90945" integrity sha512-JASD0QVVgSVleVhA9TeA+UBx+shq887hm/L+09qjZLrqIUvJZHZU+oOnhMFGot02Yop+LKfkvf9KSsTNlu/Rwg== dependencies: ... babel-jest "23.6.0"

roberthchapman avatar Jan 30 '19 16:01 roberthchapman

Since you are using yarn, I would use yarn resolution to pin babel-jest to 23.6

https://yarnpkg.com/lang/en/docs/selective-version-resolutions/

bugzpodder avatar Jan 31 '19 10:01 bugzpodder

Sorry, I was reviewing a lot of issues yesterday and didn't see that @roberthchapman. I did spot the npm ls babel-jest and hooked onto that.

I think, as @bugzpodder, using resolution is a good solution. I've used it before and it can help.

To be clear, did you try to follow those steps? Apart from removing the package from package.json? And if so, did that help?

mrmckeb avatar Feb 01 '19 07:02 mrmckeb

Hi, sorry I hadn't responded yet but I was trying to get it clear what to come back with. I had a lot of trouble understanding the one example I had for yarn resolutions, which wasn't Windows-specific. I tried a number of attempts, the latest of which was this...

"resolutions": { "[email protected]/jest": "23.6.0", "react-aad-msal@^0.4.1/jest": "22.1.4", "[email protected]/babel-jest": "23.6.0", "react-aad-msal@^0.4.1/babel-jest": "22.4.4", "jest-runtime@^22.4.4/babel-jest": "22.4.4" },

Is this the right syntax? It seemed that there were potentially many more to work through but I wasn't sure whether it was helping based on the errors I saw (apologies that I didn't save the last error). The problem is that each time, to try it I have to delete all the node_modules, change the package.json and then install again which makes it easy to spend half a day trying a few possibilities. I've worked with React for a year and never come across this before despite having used hundreds of packages, is there likely something different with this package that would see it causing these conflicts? It seems to me that jest shouldn't be being released as part of the package and rather it should be a dev dependency?

Btw, just to cover off your other question, there is no babel-jest or jest packages listed in package.json to simply remove. If there was, this would be simple. It's installed as part of react-aad-msal.

roberthchapman avatar Feb 01 '19 08:02 roberthchapman

Hi, the simplest way to override resolutions is to just specify the package name and the version, eg: "resolutions": { "babel-jest": "23.6.0", "package-b": "5.0.0", "package-c": "1.5.2" }

The reason why it only broke for react-aad-msal is because they list jest and babel-jest as a dependency rather than a dev-dependency, meaning that according to them they need jest to run their package, which is probably not true. You can file a ticket for them to move it to dev-dependency in their package.json.

You can also try selective resolutions https://juffalow.com/javascript/how-yarn-resolutions-can-save-you but I would say don't worry about it.

If it doesn't work, I would just install babel-jest and pin it to 23.6.0 in your package.json, that may get around the issue as well.

bugzpodder avatar Feb 02 '19 19:02 bugzpodder

Yes, I've used the approach that @bugzpodder recommends and it has worked for me on projects a few times. And I agree, this shouldn't be a dependency of that project (unless it's actually using it in production somehow).

Please report back and let us know how it goes.

mrmckeb avatar Feb 03 '19 09:02 mrmckeb

Thanks so much for the assistance, the solution is actually a lot simpler than what I thought I was meant to be trying. It's just forcing all packages to use the same version, simple. And much more simple than the examples I could see. All I had to do was:

  1. yarn remove react-aad-msal
  2. add "resolutions": { "jest": "23.6.0", "babel-jest": "23.6.0" }, to package.json
  3. yarn install
  4. yarn add react-aad-msal

and that's it!

roberthchapman avatar Feb 04 '19 09:02 roberthchapman

Thanks for the update @roberthchapman.

mrmckeb avatar Feb 04 '19 09:02 mrmckeb