Skip to content
Community

EXPLORE TOPICS

Editorial approach

New to CoreTrailKit?

Observe your services. Keep the evidence close.

CoreTrailKit
Back to articles
GUIDE/ npm

npm ENOENT: run from the intended project

npm run build fails because it cannot open package.json. Before changing dependencies, compare the path in the error with the directory containing the actual application package.

By CoreTrailKit3 min read

01

Read the missing path exactly

ENOENT indicates that an expected filesystem entry was not found. Confirm whether the error names package.json, a script file, or a different path. Those failures need different investigations.

Our fixture had a valid project and an empty sibling directory. Running npm run build in the empty directory failed while opening a manifest. No package download, authentication, or dependency resolution was involved.

02

Inspect the current directory and project selection

Check the working directory used by the terminal, CI step, Docker stage, or IDE task that launches npm. A repository root and the directory containing a particular package are not always the same.

The following diagnostics are for a plain package investigation. npm prefix is not workspace-aware; use the workspace’s declared structure when investigating a monorepo rather than treating its output as a complete workspace map.

sh · EXAMPLE
pwd
npm prefix
# Inspect the package.json at the intended project path.

03

Point to the existing package

In the lab layout, project and empty are sibling directories. From empty, selecting ../project ran the build belonging to the existing package. An explicit prefix can be useful when a runner’s working directory is intentionally elsewhere.

The path below is relative to the reproduction layout. In the real launcher, use the appropriate checked-out or mounted package path and verify it exists before invoking the build.

sh · EXAMPLE
# From the empty sibling of the actual project directory:
npm --prefix ../project run build

04

Verify which script was reached

The fixture build script printed project build reached. This confirmed that npm selected the intended package rather than merely finding any package.json in the directory tree.

For the real application, check the script name, package identity, and expected output artifact. Creating a fresh empty package.json in the wrong directory may remove one ENOENT while leaving the actual project unbuilt.

05

Repair the directory source in automation

Update the CI working-directory, container WORKDIR/COPY layout, or task configuration responsible for the mismatch. A one-off cd in a terminal does not repair a runner that will start from the wrong location again.

If the package path is correct but absent in a container, inspect the checkout and copy or mount steps. Keep that packaging problem separate from npm dependency issues. Verify the next clean run from the same automation entry point.

Know the limits

Reproduced with npm 12.2.1 and Node.js 24.22.1 in a disposable Linux container using local fixtures, with external networking disabled during tests. Running a build from an empty sibling directory produced ENOENT. Selecting the existing project through --prefix reached its build script. Workspaces, framework builds, deployment mounts, and real application compilation were not tested in this case.

Sources & further reading

A technical publication by CoreTrailKit.

Browse all articles

CONTINUE EXPLORING