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.
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
- Confirm
package.jsonexists where the step runs (ls package.json). - Add a
working-directoryorcdso the command runs in the project root. - Re-run from the directory that contains the manifest.
- run: node dist/index.js
working-directory: ./appCopy the manifest into the build artifact
When packaging (for example in Docker), ensure package.json is copied alongside the code that needs it.
COPY package.json package-lock.json ./
COPY dist ./distHow to prevent it
- Run scripts from the directory that holds
package.json. - Include the manifest in any artifact or image you ship.
- Set
working-directoryexplicitly in multi-package repos.