/errors/npm/enoent-could-not-read-package-json
npm error code ENOENT: Could not read package.json
- tool
- npm
- versions
- npm 7 – 11
- os
- any
npm error code ENOENT ... Could not read package.json: Error: ENOENT: no such file or directory means npm looked for package.json in the current directory and found nothing. ENOENT is the operating system's "no such file or directory" code. npm does not search parent folders for scripts and project commands, so run it from the project root (the folder that contains package.json), or create the file with npm init -y.
Reproduce it
npm run build 2>&1 | sed -E 's/[0-9T_:.-]+Z-debug-0\.log/<timestamp>-debug-0.log/'
echo "exit status: ${PIPESTATUS[0]}"Output
npm error code ENOENT npm error syscall open npm error path /tmp/work/package.json npm error errno -4058 npm error enoent Could not read package.json: Error: ENOENT: no such file or directory, open '/tmp/work/package.json' npm error enoent This is related to npm not being able to find a file. npm error enoent npm error A complete log of this run can be found in: /tmp/work/.npm-cache/_logs/<timestamp>-debug-0.log exit status: 127
The path in the message (/tmp/work/package.json here) is where npm looked; compare it with where your package.json is. The errno value and the exit status are platform-specific (this run was on Windows, where ENOENT is errno -4058); scripts should only test for a non-zero status.
Fix
npm init -y >/dev/null
npm pkg set scripts.build="echo building"
npm run buildOutput
> work@1.0.0 build > echo building building
In CI and Docker
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm ci
COPY . .- run: npm ci
working-directory: frontend