Skip to content

[BUG] npm run changes user using default (1000) instead of root (0) #4589

@robertsLando

Description

@robertsLando

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

If we have a script like "test": "node -p \"process.getuid()\"" defined in package.json when we run it with npm run test it should output 0 but it prints 1000 instead (node user). If we lunch the same command without using npm run the output is correct:

root@7f44813ba8d7:/app# node -p "process.getuid()"
0
root@7f44813ba8d7:/app# npm run test

> @app/[email protected] test
> node -p "process.getuid()"

1000
root@7f44813ba8d7:/app# node -v
v16.13.2

Expected Behavior

When I run a script as root process.getuid() should return 0 even when running that script using npm run

Steps To Reproduce

Described above

Environment

  • npm: 8.1.2
  • Node.js: 16.13.2
  • OS/System/Arch: Linux 360f89fb056b 5.13.0-35-generic #40~20.04.1-Ubuntu SMP Mon Mar 7 09:18:32 UTC 2022 x86_64 GNU/Linux
  • npm config:
; "user" config from /root/.npmrc

unsafe-perm = true 
user = "0" 

; node bin location = /usr/local/bin/node
; cwd = /app
; HOME = /root
; Run `npm config ls -l` to show all defaults.

I did my tests on a docker container but I was able to reproduce the issue evn outside docker

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next stepsRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions