← Home ← Codex ← DEBT ← Engine
Browse by Category
+ added · updated 7d
← Back to glossary

package.json & npm — Alongside composer.json

JavaScript npm3 Beginner
debt(d3/e3/b5/t7)
d3 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'default linter catches the common case' (d3). Detection hints cite npm-audit, snyk, and dependabot as automated tools that catch common mistakes like missing package-lock.json or using npm install in CI. These are standard ecosystem tools with automated detection capability, though they require explicit setup and don't catch silently.

e3 Effort Remediation debt — work required to fix once spotted

Closest to 'simple parameterised fix' (e3). The quick_fix is explicit: 'Commit package-lock.json and use npm ci in CI.' This involves a one-file addition (package-lock.json) and a one-line substitution (npm install → npm ci), which is a small, localised remediation within the build configuration. No cross-cutting refactoring required.

b5 Burden Structural debt — long-term weight of choosing wrong

Closest to 'persistent productivity tax' (b5). The term applies to contexts: web and cli, and affects any developer working with JavaScript dependencies in a PHP+JS hybrid project. The choice of dependency manager discipline (package-lock.json, npm ci vs install) influences build reproducibility, CI configuration, and onboarding patterns across the team. It's a recurring friction point but not architectural; many work streams touch dependency setup.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7). The misconception field directly states the trap: 'npm install is safe in CI and production' — this contradicts the parallel discipline developers learn in PHP (composer.lock + composer install). The 'obvious' choice (npm install) is subtly wrong in CI contexts, violating the principle of least surprise when analogy to composer suggests equivalence. This is a documented gotcha that most developers eventually learn but often by incident in production.

About DEBT scoring →

Also Known As

package.json npm node_modules yarn pnpm

TL;DR

package.json manages JS dependencies and build scripts for PHP projects using JavaScript — the npm counterpart to Composer.

Explanation

dependencies vs devDependencies: runtime JS deps vs build tools. scripts: run build tasks (npm run build, npm run dev). package-lock.json (or yarn.lock, pnpm-lock.yaml) pins exact versions — equivalent to composer.lock. Always commit the lock file. npm ci (not npm install) in CI for deterministic installs. Workspaces for monorepos. PHP projects typically have both composer.json (PHP deps) and package.json (JS deps) at the root.

Common Misconception

npm install is safe in CI and production — npm install may update packages within semver ranges; use npm ci (clean install) in CI for reproducible builds from the lock file, just like composer install.

Why It Matters

PHP projects with JavaScript frontends have two dependency managers — misunderstanding package.json vs composer.json leads to non-deterministic builds and version drift.

Common Mistakes

  • Not committing package-lock.json — same as not committing composer.lock
  • npm install in CI instead of npm ci
  • Committing node_modules — add to .gitignore like vendor/
  • devDependencies in production image increasing attack surface

Code Examples

✗ Vulnerable
# Non-deterministic — may install different versions:
npm install
# node_modules committed to git (like committing vendor/)
✓ Fixed
# Deterministic from lock file (like composer install):
npm ci

# Dockerfile production — no devDependencies:
RUN npm ci --omit=dev

# .gitignore:
# node_modules/
# dist/           (built assets)
# .env            (keep both .env.example files)

Added 17 Mar 2026
Edited 22 Mar 2026
Views 93
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings S 0 pings M 0 pings T 1 ping W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 0 pings T 0 pings W 1 ping T 0 pings F 1 ping S 1 ping S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 1 ping S 0 pings M
No pings yet today
Amazonbot 1
Amazonbot 10 PetalBot 10 SEMrush 9 Ahrefs 7 Perplexity 5 Google 4 Unknown AI 3 Meta AI 2 Majestic 2 ChatGPT 2 Scrapy 2 Twitter/X 2 Applebot 2 Brave Search 1 Bing 1
crawler 56 crawler_json 4 pre-tracking 2
🧱 FUNDAMENTALS — new to this? Start with the ground floor.
JavaScript javascript The programming language of the browser — it reads and modifies the page (the DOM), reacts to user events, and fetches data without reloading.

JavaScript is the only language browsers execute, so every interactive behaviour on the web goes through it. Its two defining traits — single-threaded event loop and loose typing (== coercion) — explain the majority of both its bugs and its design patterns.

💡 Default to const, use === always, and reach for let only when a value genuinely reassigns.

Ask Codex about JavaScript →
Package general A package is a bundle of pre-written code that you can download and use in your project instead of writing everything from scratch.

Packages let you build on tested, maintained code instead of reinventing common solutions. Understanding packages is essential because nearly every modern project relies on dozens or hundreds of them.

💡 Before installing any package, check its last update date and weekly downloads—abandoned packages become security liabilities.

Ask Codex about Package →
DEV INTEL Tools & Severity
🟡 Medium ⚙ Fix effort: Low
⚡ Quick Fix
Commit package-lock.json and use 'npm ci' in CI — same discipline as composer.lock and 'composer install'
📦 Applies To
javascript npm3 web cli
🔗 Prerequisites
🔍 Detection Hints
npm install in CI Dockerfile; package-lock.json not committed; node_modules in .gitignore missing
Auto-detectable: ✓ Yes npm-audit snyk dependabot
⚠ Related Problems
🤖 AI Agent
Confidence: Medium False Positives: Medium ✗ Manual fix Fix: Medium Context: File
CWE-1104


✓ schema.org compliant