TGViewer
Web Development Web Development @web_dev_bds · 4.44K subscribers
Post #1014 398
What Actually Happens During npm install

npm install does far more than download packages.
It first reads your package.json.

Then it looks at your package-lock.json, which records the exact dependency versions your project expects.
Next it builds a dependency tree.

If Package A needs React 18.2.0 and Package B also needs React 18.2.0, npm can reuse that version.

If another package requires React 17, npm may install both versions because their requirements don't match.

Only after resolving that entire tree does npm download packages and place them into node_modules.

That's why deleting package-lock.json can unexpectedly change working code.

The lock file isn't just a cache. It's a snapshot of the dependency tree your project was built and tested with.
  • 👍 2
More from @web_dev_bds
  1. Oct 9, 2026JavaScript CheatSheet
  2. Oct 8, 2026📕Pro tip if you're using Postgres: Set `application_name` in your app's DB connector/ORM/…
  3. Oct 7, 2026🚀 Beginner → Developer: What to Learn in 6 Months Want to become job-ready but don't know…
  4. Oct 6, 2026React vs Angular
  5. Oct 5, 2026Post #1048
  6. Oct 5, 2026⚡️ 10 VS Code Extensions That Are Actually Useful If you use VS Code for coding, these ext…
Threads Profile ViewerView any public Threads profile without an account.Open ThreadLook →Writing with AI? Make it sound human.Metric37 rewrites AI drafts so they read naturally. Free AI detector, 1,500 words free.Try Metric37 →