Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

npm link and multiple levels of peerDependencies = psychedelic mess #5080

@mpj

Description

@mpj

So npm link behaves in (what I think is) an unexpected way when you multiple levels of packages that depend on the same peerDependency.

Look at the dependency chain below. I have a Knockout app, spotify-app, that relies on a spotify-framework module that in turn relies on a spotify-library module. All three depend on knockout and it's very important that there is only one instance of Knockout in the app because reasons. Thus, spotify-app requires knockout as a normal dependency, and the spotify-framework and spotify-library module both list it as a peerDependency. This dependency chain works fine, until you decide to do development on the spotify-framework module and try to use npm link - then the mad hatter comes in and gives you spiked cookies and everything goes pink fluffy unicorns dancing on rainbows.

This is what happens: You happily clone the spotify-framework from git, and then you run npm link in its directory, in preparation of linking it in from spotify-app. The problem here is that npm link will run spm install (I think) under the hood. npm will look at the peerDependencies of spotify-library, and then install an instance of knockout inside the node_modules of spotify-framework, because it thinks that spotify-framework is the top-level module. This will silently cause _duplicate versions_ on knockout, because spotify-app will install another instance of knockout itself. It's obvious what happens when I write it down like this, but it was extremely confusing to figure out what happened here, I tell you.

I'm not sure how this should be solved, but I'm leaning towards that npm link should never install peerDependencies on it's own, because it's most likely not the top-level module if it's being linked.

{
  "name": "spotify-app",
  "version": "0.0.1",
  "private": "true",
  "dependencies": {
    "knockout": "~3.0.0",      
    "spotify-framework": "0.0.1"
  }
}

{
  "name": "spotify-framework",
  "version": "0.0.1",
  "private": "true",
  "peerDependencies": {
        "knockout": "^3.0.0",
  },
  "dependencies": {
    "spotify-library": "0.0.1"
  }
}

{
  "name": "spotify-library",
  "version": "0.0.1",
  "private": "true",
  "peerDependencies": {
        "knockout": "^3.0.0",     
  }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions