npm Community Forum (Archive)

The npm community forum has been discontinued.

To discuss usage of npm, visit the GitHub Support Community.

Install aliased peer dependency


I’ve been facing an issue with dependencies. I’m using leaflet and react-leaflet in my project but turns out I need two different components in two different versions.

I’ll explain further:

One part of my application needs react-leaflet@^0.12.3 and leaflet@^0.7.0.

However, the rest of my code needs react-leaflet@^2.4.0 and leaflet@^1.5.0.

This wasn’t a problem since I used this command to install multiple versions as aliased packages:

npm install leaflet react-leaflet leaflet-legacy@npm:leaflet@0.7.0 react-leaflet-legacy@npm:react-leaflet@0.12.3

Everything works fine until I get our well known warning message:

npm WARN react-leaflet@0.12.3 requires a peer of leaflet@^0.7.0 but none is installed. You must install peer dependencies yourself.

So how can I use both versions in my code but also solve peer dependency issues?

Any suggestion?
Thanks in advance!

A (heavy) option would be to split out the code needing the old version into a separate package so you can specify the required dependencies independently from your main package?

It could work, but the project will definitely become unreadable at some point, since the main package will also include the independent package.

I was thinking of going back to npm2 where dependencies are installed and duplicated inside the node_modules folder; but I can’t force any other programmer to run my application only with npm2.