After struggling with this for weeks, I have finally found the root cause and it is really dumb of me to not pay attention to that, I don't want others to make the same mistake. Since the code is proprietary, I can't share it. But I will explain the problem.
The image with nodejs:16
uses npm
8.0 whereas the one with nodejs:14
uses some npm
version < 8.0.
The difference between them is in version 8.0, npm
will also install the dependencies listed within peerDependencies
block. (I am unsure if this behavior started from npm 8.0 or some previous versions)
So, why did I think npm is installing both devDependencies
as well as dependencies
?
When I was working with the nodejs:14
image, I moved certain dependencies from dependencies
block to devDependencies
block. So when I upgraded to nodejs:16
, those dependencies returned.
Actually, the reason they came back because they were being internally used by a transitive dependency, which was listed within peerDependency
block of package.json
.
So, the takehome lesson?
Make sure the dependency you want to be removed isn't being consumed directly or transitively within dependency
as well as peerDependency
block.