Skip to content
Latchkey

Node "ENOENT: package.json" during module resolution in CI

Node walks up the directory tree reading package.json to decide a file's module type and resolve packages. An ENOENT means the file it expected (often in the working directory or a dependency) is missing.

What this error means

A run fails with "Error: ENOENT: no such file or directory, open '/app/package.json'" while Node is resolving modules or determining the module type.

node
Error: ENOENT: no such file or directory, open '/app/package.json'
    at Object.openSync (node:fs:603:3)
    at readPackageScope (node:internal/modules/cjs/loader:...)

Common causes

Running from a directory with no package.json

The CI step started in a path where no package.json exists, so type and dependency resolution cannot read it.

A checkout or build that omitted package.json

A partial copy (Docker COPY of only some files, an artifact missing the manifest) left the runtime without the manifest it needs.

How to fix it

Run from the package root

  1. Confirm package.json exists where the step runs (ls package.json).
  2. Add a working-directory or cd so the command runs in the project root.
  3. Re-run from the directory that contains the manifest.
.github/workflows/ci.yml
- run: node dist/index.js
  working-directory: ./app

Copy the manifest into the build artifact

When packaging (for example in Docker), ensure package.json is copied alongside the code that needs it.

Dockerfile
COPY package.json package-lock.json ./
COPY dist ./dist

How to prevent it

  • Run scripts from the directory that holds package.json.
  • Include the manifest in any artifact or image you ship.
  • Set working-directory explicitly in multi-package repos.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →