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 i -w <ws> <dep> sets dependency version to * in package-lock.json #5587

Closed
2 tasks done
legastero opened this issue Sep 26, 2022 · 0 comments
Closed
2 tasks done
Assignees
Labels
Bug thing that needs fixing Priority 1 high priority issue Release 8.x work is associated with a specific npm 8 release

Comments

@legastero
Copy link

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

Using npm install -w <workspace> <dep>, where <dep> does not include an @ version, then the generated package-lock.json updates the dependencies for <workspace> as <dep>@*.

The dependency version is always correctly set in the workspace's package.json.

If you use npm i -w <workspace> <dep>@latest or any specific tag/version, then things behave as expected.

Expected Behavior

The version of <dep> for <workspace> in package-lock.json should be set to the version that got installed.

Steps To Reproduce

  1. In a repo with this layout:
- package.json
- workspaces/
  - a/
    - package.json

and where the root package.json looks like:

{
  "name": "test-npm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "workspaces": ["workspaces/*"]
}

and workspaces/a/package.json looks like:

{ 
  "name": "a",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC"
} 
  1. Using npm 8.19.2 (or even 9.0.0-pre.2)
  2. Run npm i -w a react
  3. Open generated package-lock.json and see:
  "dependencies": {
    "a": {
      "version": "file:workspaces/a",
      "requires": {
        "react": "*"
      }
    },

whereas workspaces/a/package.json was updated to be:

{
  "name": "a",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "react": "^18.2.0"
  }
}
  1. If you run npm i a second time, then the package-lock.json updates to appear as originally expected:
  "dependencies": {
    "a": {
      "version": "file:workspaces/a",
      "requires": {
        "react": "^18.2.0"
      }
    },

Environment

  • npm: both v8.19.2 and v9.0.0-pre.2
  • Node.js: v16.14.2
  • OS Name: macOS
  • System Model Name: MacBook Pro
  • npm config:
; "user" config from /Users/lance/.npmrc

//registry.npmjs.org/:_authToken = (protected) 

; node bin location = /Users/lance/.nvm/versions/node/v16.14.2/bin/node
; node version = v16.14.2
; npm local prefix = /Users/lance/Developer/test-npm
; npm version = 8.19.2
; cwd = /Users/lance/Developer/test-npm
; HOME = /Users/lance
; Run `npm config ls -l` to show all defaults.```
@legastero legastero added Bug thing that needs fixing Needs Triage needs review for next steps Release 8.x work is associated with a specific npm 8 release labels Sep 26, 2022
@wraithgar wraithgar added Priority 1 high priority issue and removed Needs Triage needs review for next steps labels Oct 5, 2022
@wraithgar wraithgar self-assigned this Jan 25, 2023
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 1 high priority issue Release 8.x work is associated with a specific npm 8 release
Projects
None yet
Development

No branches or pull requests

2 participants