Question presented to candidate: "Your production Docker image installs with npm install --omit=dev, and the app crashes because a package it imports at runtime is missing. What is the likely mistake in package.json?"
What a strong answer should cover:
"dependencies"are packages the application needs at runtime in production — anything actuallyrequired/imported by code that runs when the app is live."devDependencies"are packages needed only for development and build tooling — test runners, linters, TypeScript, bundlers — never imported by the shipped runtime code itself.- 📌 The concrete, verifiable consequence:
npm install --omit=dev(or the older--productionflag) installs only"dependencies", skipping everything under"devDependencies"entirely — the exact bug in the prompt is a runtime import placed in"devDependencies"by mistake. "peerDependencies"are different in kind, not just in timing: they declare that this package expects the consuming project to already provide a compatible version of something (a classic example: a plugin declaring the specific version range of the framework it plugs into) — npm does not automatically install a peer dependency's package the way it does regular dependencies; it instead warns if a compatible version is missing or the wrong version is present in the consuming project."optionalDependencies"(less commonly asked about, but worth naming precisely if it comes up) behave like regular dependencies except an install failure for one of them does not fail the whole install — used for packages that provide an enhancement but are not strictly required.- A precise answer keeps the framing correct: this is fundamentally about when and for whom a package is needed (build-time-only tooling vs. runtime code vs. "the consumer is expected to already have this"), not merely a stylistic categorization choice.
Clarifying questions expected:
- "Is this package imported by code that runs in production, or only used by a build/test script?" — the actual deciding question between
dependenciesanddevDependencies. - "Is this project a library meant to be installed by other projects, or an application?" —
peerDependenciesmatters far more for the former.
Code / implementation expected: Yes — demonstrating npm install --save-dev correctly placing a package under devDependencies, and a production-style install skipping it, is the concrete, convincing proof.