Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
mehulkar opened this issue Nov 3, 2023 · 3 comments · May be fixed by #7208
Open
2 tasks done

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

mehulkar opened this issue Nov 3, 2023 · 3 comments · May be fixed by #7208
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 9.x work is associated with a specific npm 9 release

Comments

@mehulkar
Copy link

mehulkar commented Nov 3, 2023

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.
@mehulkar mehulkar added Bug thing that needs fixing Needs Triage needs review for next steps Release 9.x work is associated with a specific npm 9 release labels Nov 3, 2023
@ljharb
Copy link
Contributor

ljharb commented Nov 3, 2023

Just curious; why are you using --prefix if you're already in the desired directory?

@mehulkar
Copy link
Author

mehulkar commented Nov 3, 2023

That's a great question and I don't know. It was in a CI script we had that was previously only running on macOS/Linux and I'm working on making it run on Windows. I'm planning to stop using it --prefix, but felt it was worth filing. Couldn't find documentation here either.

@wraithgar wraithgar added Priority 2 secondary priority issue and removed Needs Triage needs review for next steps labels Nov 7, 2023
ficocelliguy added a commit to ficocelliguy/cli that referenced this issue Feb 7, 2024
@ficocelliguy
Copy link

#7208 filed to resolve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug thing that needs fixing Priority 2 secondary priority issue Release 9.x work is associated with a specific npm 9 release
Projects
None yet
4 participants