Skip to content

[BUG] ENOENT on npm exec if prefix directory doesn't exist #5942

@cbay

Description

@cbay

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

Starting with 19a8346, a simple npm exec foo fails with ENOENT if the prefix directory specified in npmrc doesn't exist:

$ npm exec foo
npm ERR! code ENOENT
npm ERR! syscall lstat
npm ERR! path /home/cbay/.npm-packages/lib
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, lstat '/home/cbay/.npm-packages/lib'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

$ cat ~/.npmrc 
prefix = /home/cbay/.npm-packages

$ ls /home/cbay/.npm-packages
ls: cannot access '/home/cbay/.npm-packages': No such file or directory

Expected Behavior

It used to work just fine until that commit:

$ npm exec foo
Need to install the following packages:
  foo@0.0.7
Ok to proceed? (y)

Steps To Reproduce

No response

Environment

This was tested on Node.js 18.8.0 and 19.1.0. It worked fine on 18.7.0.

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