skip to Main Content

I’m working on a node project that involves an SDK and then a parent project consuming the SDK. In Java, maven or gradle will pick transitive dependency with the highest version number but how does that work in npm?

From the screenshot below, the SDK imports debug package with version 4.3.4 which is what I want to see in the parent project. However, npm picked the version 2.6.9 instead. I have tried defining the library version from dependencies or overrides section from SDK, none of them works.

I know that I can add an overide from parent project to force the newer version but am I doing something wrong that causes this or overriding dependency from parent project is the only way to resolve this? Is there something I can do in the SDK to enforce this library version from the consuming parent projects?

enter image description here

Base on the package-lock.json file, I looked into the actual debug package json file under the node_modules folder and confirmed that it is at version 2.6.9

enter image description here

2

Answers


  1. In Java, maven or gradle will pick transitive dependency with the highest version number but how does that work in npm?

    That is indeed one of the big differences between npm and Maven/gradle, regarding management of dependencies:

    • Java handles only a single version of any given package per project. Therefore Maven and gradle have to choose a single common version of each dependency, even for transitive dependencies, which can possibly break their intermediate parent (start of the so called dependencies hell)
    • Node module resolution is per package: each module can have its own node_modules folder, containing its own dependencies and specific version. It can still share dependencies though: Node walks up the folder tree until it finds a node_modules containing the dependency; this way it factorizes compatible versions.

    This is what you see in your case:

    Therefore if you inspect your actual folder structure, there should be no [email protected], only 4.3.4

    Login or Signup to reply.
  2. Downgrade the node (npm) version to the required stable version and use npm update in terminal of visual Studio code.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search