Challenge 3: Diagnose a Missing Checkout — Possible Solution ==================================================================== THE SCENARIO ------------- A workflow's first step is run: npm install (no actions/checkout beforehand), and it fails immediately with an error about a missing package.json. WHY THIS HAPPENS ----------------- Per Chapter 2's core point about job isolation — reinforced directly in this chapter's own tip box — every job runs on a completely fresh runner that starts with an EMPTY filesystem. There's no automatic mechanism that puts the repository's code onto that runner; it has to be explicitly fetched via actions/checkout as an actual step in the workflow. Without that step ever running, the runner genuinely has no files from the repository at all — not package.json, not any source code, nothing. When npm install then runs as the very first step, it looks in the current working directory for a package.json to read (to know what dependencies to install) — and finds nothing there at all, because the runner's filesystem is still in its pristine, empty starting state. The resulting error ("missing package.json" or similar) isn't a bug in npm install itself; it's the direct, expected consequence of trying to run a command that depends on repository files existing, on a machine that was never given those files in the first place. WHY THIS ISN'T ABOUT npm install BEING WRONG -------------------------------------------------- This chapter is explicit that this exact failure mode is "not because those commands are wrong, but because there's simply no repository present to run them against." The fix has nothing to do with how npm install is invoked or configured — the missing piece is an entirely separate, prior step: adding actions/checkout@v4 (or the current version) as the FIRST step in the job, before npm install or any other command that assumes the repo's files are already present. THE FIX -------- steps: - uses: actions/checkout@v4 # <-- the missing, required first step - run: npm install - run: npm test Adding this one line resolves the failure entirely, since the runner now actually has the repository's files (including package.json) present before npm install ever tries to read them.