Skip to content

[BUG] Why is npm run writing into the .npm/_logs directory or creating it? #7032

@JJ

Description

@JJ

Is there an existing issue for this?

  • I have searched the existing issues

This issue exists in the latest npm version

  • I am using the latest npm

Current Behavior

npm run is creating if it does not exist and writing if it exists into the .npm/_logs directory.

Expected Behavior

Even if logs are turned off completely with the --logs-max=0 option, the directory is still created. This calls for workarounds if the current directory is not writable (a relatively common scenario if you're working inside a container) or workarounds, but there is apparently no way to turn it off completely.

Steps To Reproduce

This Dockerfile:

FROM node:21-alpine

RUN mkdir -p /app/test && chown -R node:node /app && npm install -g npm@latest

USER node

WORKDIR /app

COPY package.json ./

WORKDIR /app/test

ENTRYPOINT ["npm", "--logs-max=0", "run", "test"]

With this package.json

{
  "name": "dotnpm-created",
  "version": "1.0.0",
  "description": "Test file",
  "main": "index.js",
  "scripts": {
    "test": "echo \"test\""
  },
  "author": "",
  "license": "ISC"
}

When run with:

podman run --rm -it -v `pwd`:/app/test -u 1001 jjmerelo/dotnpm-test

It creates a .npm file with:

.npm:
total 12
drwxr-xr-x 3  101000 jmerelo 4096 nov 28 14:38 .
drwxrwxr-x 3 jmerelo jmerelo 4096 nov 28 14:38 ..
drwxr-xr-x 2  101000 jmerelo 4096 nov 28 14:38 _logs

.npm/_logs:
total 8
drwxr-xr-x 2 101000 jmerelo 4096 nov 28 14:38 .
drwxr-xr-x 3 101000 jmerelo 4096 nov 28 14:38 ..

So it still has an empty log directory.

Environment

  • npm@10.2.4
  • node@v21.2.0
  • Alpine OS
  • npm config:
; node bin location = /usr/local/bin/node
; node version = v21.2.0
; npm local prefix = /app
; npm version = 10.2.4
; cwd = /app/test
; HOME = /home/node

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions