Skip to content

[BUG] npm refuses to run if the home directory is inaccessible #4769

Closed
@ChlodAlejandro

Description

@ChlodAlejandro

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

Currently happens on npm 8.6.0 and later. Attempting to run any npm command if the user's home directory does not exist (possible for system-only Linux users) makes npm exit without having output anything (well, it does output a newline) and returns with an error code of 243.

Expected Behavior

npm commands should work as expected. Even basic commands, such as showing the version (npm -v) provide no output and also exit with the aforementioned error code.

Steps To Reproduce

  1. Have no home directory (sudo adduser --system --no-create-home test)
  2. Install npm 8.6.0 or 8.7.0.
  3. Attempt to run any npm command.

The following shell logs demonstrate the issue. Reproduction done in a Debian docker container to avoid spinning up a whole VM just to test this with a clean slate.

root@c2f1f15a3d97:/test# npm i -g npm@8.5.0

added 1 package, and audited 218 packages in 8s

11 packages are looking for funding
  run `npm fund` for details

1 moderate severity vulnerability

To address all issues, run:
  npm audit fix

Run `npm audit` for details.

root@c2f1f15a3d97:/test$ npm -v
8.5.0
root@c2f1f15a3d97:/test# su test -s /bin/bash
test@c2f1f15a3d97:/test$ ls ~
ls: cannot access '/home/test': No such file or directory
test@c2f1f15a3d97:/test$ npm -v
8.5.0
test@c2f1f15a3d97:/test$ exit
exit
root@c2f1f15a3d97:/test# npm i -g npm@8.6.0

removed 20 packages, changed 63 packages, and audited 201 packages in 7s

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.5.0 -> 8.7.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v8.7.0
npm notice Run npm install -g npm@8.7.0 to update!
npm notice
root@c2f1f15a3d97:/test# su test -s /bin/bash
test@c2f1f15a3d97:/test$ npm -v

test@c2f1f15a3d97:/test$ npm -ddd -v

test@c2f1f15a3d97:/test$ npm -v --timing

test@c2f1f15a3d97:/test$ echo $?
243
test@c2f1f15a3d97:/test$ ls -la
total 8
drwxr-xr-x 2 test root 4096 Apr 17 11:45 .
drwxr-xr-x 1 root root 4096 Apr 17 11:45 ..
test@c2f1f15a3d97:/test$ exit
exit
root@c2f1f15a3d97:/test# npm i -g npm@8.7.0

removed 6 packages, changed 50 packages, and audited 197 packages in 19s

10 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
root@c2f1f15a3d97:/test# npm -v
8.7.0
root@c2f1f15a3d97:/test# su test -s /bin/bash
test@c2f1f15a3d97:/test$ npm -v -ddd

test@c2f1f15a3d97:/test$ echo $?
243
test@c2f1f15a3d97:/test$

Environment

  • npm: 8.6.0, 8.7.0
  • Node.js: v16.14.2
  • OS Name: Debian
  • System Model Name: Hetzner CX21 Virtual Private Server
  • npm config:
; npm config -ls returns no output.

Metadata

Metadata

Assignees

Labels

Bugthing that needs fixingPriority 1high priority issueRelease 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