Skip to content

[BUG] npm install --prefix="$PWD" adds invalid dependency to package.json #6960

@mehulkar

Description

@mehulkar

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

mkdir project && cd project
echo "{\"name\": \"project\"}" > package.json
npm install --prefix="$PWD"

On macOS, this does the expected thing (generates a package-lock.json:

{
  "name": "project",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "project"
    }
  }
}

On Windows, however, it does strange things. It:

  • Adds { "dependencies": { "project": "file:" }} to package.json
  • Generates a package-lock:
    {
      "name": "project",
      "lockfileVersion": 3,
      "requires": true,
      "packages": {
        "": {
          "name": "project",
          "dependencies": {
            "project": "file:"
          }
        },
        "node_modules/project": {
          "resolved": "",
          "link": true
        }
      }
    }
  • Generaetes node_modules directory with a symlink project pointing to PWD

Expected Behavior

I expect Windows to have the same behavior. Particularly, package.json should not be modified.

Steps To Reproduce

See above

Environment

  • npm: 9.5.1
  • Node.js: v18.16.0
  • OS Name: Windows 10
  • System Model Name:
  • npm config:
; copy and paste output from `npm config ls` here
; "builtin" config from C:\Program Files\nodejs\node_modules\npm\npmrc

prefix = "C:\\Users\\mehulkar\\AppData\\Roaming\\npm"

; node bin location = C:\Program Files\nodejs\node.exe
; node version = v18.16.0
; npm local prefix = C:\Users\mehulkar\project
; npm version = 9.5.1
; cwd = C:\Users\mehulkar\project
; HOME = C:\Users\mehulkar
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueRelease 9.xwork is associated with a specific npm 9 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions