Versions, Lock Files and Virtual Environments

4.Same Ingredients, Down to the Batch Number

A

In this chapter

We'll learn how software versions work — semantic versioning explained as changes to a building — why lock files exist (an exact recipe with brand and batch number), what node_modules is, and how virtual environments and version managers keep projects from clashing.

14–16 min

The Problem in Real Life

The warning on Anna's laptop: "Unsupported engine: package next@15.0.3 requires node >=20. Current: 18.17.0." And when she finally gets the app running, one page looks slightly different from Liam's. Her install picked up a newer minor version of a date library than his.

"Two problems, one cause," John says. "We let versions float. On a team, everyone's kitchen must have exactly the same ingredients — down to the batch number."

A

Same code, same command, slightly different app. How?

Anna

"Any Recent Version" vs. Exactly the Same Versions Everywhere

Versions drift

Allowing "any compatible version" means two installs a week apart can get different code.

Some updates break things

A new version can change how a package behaves — you need to know which updates are safe.

Projects need different versions

One project needs Node 20, an older one needs Node 18. Both must live on the same laptop.

Versions, Lock Files and Virtual Environments

Semantic versioning — the building analogy: most packages use semantic versioning (SemVer): three numbers, MAJOR.MINOR.PATCH, like 15.0.3. Each number tells you what kind of change happened — think of updates to a building you live in.

  • PATCH (15.0.3 → 15.0.4) — fixing a leaky tap: bug fixes only. Nothing about how you use the building changes. Always safe to take.
  • MINOR (15.0 → 15.1) — adding a new room: new features added, but every existing room stays where it was. Your old code keeps working. Usually safe.
  • MAJOR (15 → 16) — rebuilding the floor plan: breaking changes — something you relied on was moved or removed. Your code may need changes. Upgrade on purpose, read the release notes, and test.
  • Version ranges in package.json: "^15.0.0" (caret) means "any 15.x.x — patches and minor updates OK, no major." "~15.0.0" (tilde) means "only 15.0.x — patches only." "15.0.3" with no symbol means exactly that version. Ranges are convenient, but they mean two installs on different days can get different versions — exactly Anna's problem.
Table — Semantic versioning as building changes
PartExampleBuilding versionSafe to update?
PATCH15.0.3 → 15.0.4Fixing a leaky tapYes
MINOR15.0.4 → 15.1.0Adding a new roomUsually yes
MAJOR15.1.0 → 16.0.0Rebuilding the floor planOnly on purpose, with testing
Table — Version ranges in package.json
Written asAllowsExample matches
^15.0.0Minor and patch updates15.0.3, 15.2.0 — not 16.0.0
~15.0.0Patch updates only15.0.3 — not 15.1.0
15.0.3Exactly this version15.0.3 only
>=20This version or newer20, 21, 22...
Table — Which files go in Git?
File / folderCommit it?Why
package.jsonYesThe shopping list
package-lock.jsonYesExact versions — makes everyone identical
node_modules/NoRebuilt from the two files above
.nvmrcYesWhich Node.js version the project uses
.venv/ (Python)NoEach developer creates their own
The fix, step by step
cat .nvmrc # 20 <- the Node version this project expects
nvm install # installs Node 20 (reads .nvmrc)
nvm use # switch this terminal to Node 20
node --version # v20.x
rm -rf node_modules # throw out the old pantry
npm ci # install EXACTLY what package-lock.json says
npm run dev # now identical to Liam's setup
The Python equivalent: a virtual environment
python -m venv .venv # create a private pantry for this project
source .venv/bin/activate # use it (Windows: .venv\Scripts\activate)
pip install -r requirements.txt # install this project's packages into it

Lock file — the exact recipe, with brand and batch number: a shopping list that says "some pasta" gets you different pasta every week. A lock file writes down the exact version of every package that was installed — including all the transitive dependencies — plus a fingerprint (hash) of each file. npm's is package-lock.json (Yarn: yarn.lock, pnpm: pnpm-lock.yaml, Python tools: poetry.lock and others). When the lock file exists, everyone installs the identical set. Commit the lock file to Git — it's how the team and the servers stay identical. On servers and in automated builds, use npm ci, which installs strictly from the lock file and fails if anything doesn't match.

node_modules — the pantry filled from the list: node_modules is the folder where npm puts every installed package — the pantry the shopping arrives in. It can be hundreds of megabytes and is fully rebuilt from package.json + package-lock.json, so it's never committed (it's in .gitignore, Act 15). If it ever gets into a strange state, the classic fix is to delete it and run npm install (or npm ci) again.

Virtual environments — a separate pantry for each project: if two Python projects shared one pantry, project A's Django 4 and project B's Django 5 would clash. A Python virtual environment (python -m venv .venv) gives each project its own private set of installed packages. You "activate" it while working on that project. In Node.js, each project already has its own node_modules, so packages don't clash — but Node itself does: one project needs Node 20, another Node 18. A version manager like nvm (or fnm, Volta) lets you install several Node versions and switch per project, often automatically from a small .nvmrc file in the project.

Anna's fix: she installs nvm, runs nvm install (which reads .nvmrc → Node 20), deletes node_modules, and runs npm ci so she gets exactly the versions in the lock file. Her app now matches Liam's to the last package. John notices the lock file wasn't up to date in Git — someone had added a package without committing the lock file — and fixes that too.

Key Takeaway

Semantic versioning is MAJOR.MINOR.PATCH: patch fixes a leaky tap (safe), minor adds a room (usually safe), major rebuilds the floor plan (breaking). Ranges like ^ allow updates, so a committed lock file records the exact version of every package — install from it with npm ci. node_modules is rebuilt from these files and never committed. Virtual environments (Python) and version managers like nvm (Node) keep each project's versions from clashing.

Why This Matters

"It works on my machine" is very often a version problem. Semantic versioning tells you which updates are safe; committed lock files and npm ci make every laptop and every server install the same thing; version managers and virtual environments let you work on many projects at once. In Act 19, BlueTicket's build pipeline relies on exactly this to make every deployment predictable.

The app runs on Anna's new laptop exactly like everyone else's. It took her most of a morning. She opens the project's README to see why — and finds that its setup instructions are two years old.