Notice that both packages have peer dependency npm utensils. But the version that they need is different. For npm burger, it listed care at 1.0.0, which means it can only accept anything that is greater or equal to 1.0.0, and less than 2.0.0. Now for npm fries, it accepts anything that is greater or equal to 2.0.0, but less than 3.0.0. This is like the burger wants this white plate and the fries wants this bucket. Earlier, when we install npm burger into npm restaurant, we already have npm utensils 1.0.0, the white plate, installed. Because this is a peer dependency, we can only have one version of the package installed. When we try to install npm fries, the peer dependency npm utensils 2.0.0 for fries into the npm restaurant package, we see a conflict. And that is why you would see this error from your command line, which says cannot resolve dependency, conflicting peer dependency.
So if this happens, what can you do? To fix this peer dependency problem, generally speaking, you want to look for a compatible version. That could mean looking higher, lower version of npm burger, npm fries, or look for a version that accepts the same npm utensils version. You might need to update the dependency of a dependency, or even implement overrides in package.json. The reason I cannot give you one specific solution right now is because this peer dependency problem can happen in different levels in your package.json. So really, depending on a situation, we need to use different tools to fix this.
Back to this step 3, build IDEA tree, one more thing I wanted to highlight about this step is that your package.json file does not only exist in your host application. It actually exists in every single package that you have that you install. So when the CLI is trying to build the IDEA tree, it's not just looking at the package.json of your host application. It's also looking at every single package.json of the packages that you're installing. Let's say the tree is done building, then the CLI will proceed to compare the tree differences and resolve any conflicts. It will make decisions on what needs to be done next, might be adding, removing, changing, or just do nothing. Then the CLI will proceed to download the packages needed from the registry or from cache if it's available. This is a step when errors can happen. One of them might be you pointed a wrong registry, and so you get an error. Or you might be trying to install a private package, but you don't have authorization to do it. After the packages are being downloaded by the CLI to a temporary location in an instance, then it needs to be moved to your node modules. If your project has lifecycle scripts in it, those scripts will also be run accordingly if you allow them to do. And by lifecycle scripts, I'm talking about scripts like pre-install or post-install. After that, your log file will be updated to capture all the changes that have happened. The log file captures not only the dependencies listed in your package.json, but also the dependency of the dependency.
Comments