Reading — step 1 of 5
Read
Building the Dependency Tree
Given a root package's dependencies, you recursively expand:
my-app
├── express ^4.18.0
│ ├── body-parser ^1.20.0
│ │ └── debug ^4.0.0
│ └── debug ^4.0.0
├── mongoose ^7.0.0
│ └── debug ^4.0.0
Three things to notice:
-
Same package, multiple paths:
debugappears 3 times in the tree. In JS land (npm v3+), shared deps get deduplicated at install time — the SAME copy ofdebug-4.x.xis shared. -
Conflicts at the same name: if
mongoosewanteddebug ^3.0.0andbody-parserwanteddebug ^4.0.0, you'd have a conflict. Some package managers (npm) allow MULTIPLE COPIES of the same package at different versions innode_modules. Others (Maven) refuse and require manual resolution. -
Cycles:
A depends on BandB depends on Ais rare but happens. Most resolvers tolerate it via "already visiting" checks, but installation order becomes ambiguous.
For this lesson: recursive expansion with cycle detection.
Discussion
Ask a question, share an insight, or help someone who’s stuck.
Sign in to post a comment or reply.
Loading…