Removed peer dependency doesn't be reinstalled

What I Wanted to Do

Remove a peer dependency and get it back when reinstall packages

What Happened Instead

When I reinstall all packages (npm i), the peer dependency was not reinstalled

Reproduction Steps

I’ll use Firebase and angularfire to show. In any npm project folder:

$ npm install angularfire
$ npm uninstall firebase <!-- peer dependency from angularfire -->
$ npm install

Look that the firebase dependency was not installed again.

Details

My suggestion is to allow remove explicit only dependencies on package.json (yarn behavior). Unnecessary inconsistencies can be avoided with this.

But, if community like/use that feature, updating package-lock when a peer dependency is removed must do the job.

Platform Info

npm: 6.10
node: 11.15
OS: Manjaro Linux

Are you sure firebase was uninstalled?

npm allows the package.json to specify dependencies, devDependencies, and peerDependencies: https://docs.npmjs.com/files/package.json

angularfire lists firebase in its dependencies. When you install angularfire you get firebase too.

$ npm init -y
...
$ npm install angularfire
...
$ npm ls 
$ npm ls firebase
9961@1.0.0 /Users/john/Documents/Sandpits/npm.community/9961
└─┬ angularfire@2.3.0
  └── firebase@3.9.0 

When you uninstall firebase, since it is not a direct dependency of your package, it does not get uninstalled.

$ npm uninstall firebase
...
$ npm ls firebase
9961@1.0.0 /Users/john/Documents/Sandpits/npm.community/9961
└─┬ angularfire@2.3.0
  └── firebase@3.9.0 

On a related note, peerDependencies are not automatically installed since npm v3 but there is a proposal to bring that back: https://github.com/npm/rfcs/pull/43

I can’t reproduce again and you’re right, firebase wasn’t uninstalled. I don’t know what I actually did… An info message saying that dependency was keeped is valid? wdyt?

Anyway, this was my confusion and the problem was solved, thanks!

1 Like