Skip to content

[BUG] npm update does not retain specified dependency ranges in package.json #7889

@rosstroha

Description

@rosstroha

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

npm update package --save removes some version range symbols (I have only tested ~ and ^) from package.json

Expected Behavior

It doesn't remove them.

Steps To Reproduce

  1. Fresh project created with npm init
  2. With package.json contents:
{
  "name": "npmbug",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "emoji-poop": "~1.2.0"
  }
}
  1. Run npm update emoji-poop --save
  2. The version becomes 1.2.1 instead of ~1.2.1

Environment

  • npm: 10.9.0
  • Node.js: 20.11.1
  • OS Name: Mac OS
  • System Model Name: Macbook Pro M1
  • npm config:
; "user" config from /Users/r.troha/.npmrc

<redacted>
package-lock = true
save-exact = true
save-prefix = ""

; "env" config from environment

python = "/opt/homebrew/python/bin/python3.8"

; node bin location = /Users/r.troha/.volta/tools/image/node/20.11.1/bin/node
; node version = v20.11.1
; npm local prefix = /Users/r.troha/Projects/npmbug
; npm version = 10.9.0
; cwd = /Users/r.troha/Projects/npmbug
; HOME = /Users/r.troha
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingNeeds Triageneeds review for next steps

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions