npm / npm/cli

[BUG] `npm install` ignores Git SHA changes

Open
#9,966 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

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
This is not just a request to bump a dependency for a CVE
  • This is not solely a request to bump a dependency for a CVE
Current Behavior

Changing a Git dependency’s full commit SHA in package.json, then running npm install, leaves the old commit in both package-lock.json and node_modules. The command succeeds and reports that everything is up to date.

Expected Behavior

npm install should detect that the requested commit differs from the locked commit, install the requested commit, and update package-lock.json.

Steps To Reproduce

This example uses two sibling directories: dependency contains a Git package with two commits, and consumer installs that package. Run the commands in the same Bash session.

  1. Create the dependency and its two commits.

    Both commits have the same package version but different file contents.

    mkdir git-dependency-update-test
    cd git-dependency-update-test
    mkdir dependency consumer
    
    cd dependency
    git init
    echo '{"name":"dependency","version":"1.0.0"}' > package.json
    
    echo 'old content' > content.txt
    git add .
    git commit -m "Old content"
    old_commit=$(git rev-parse HEAD)
    
    echo 'new content' > content.txt
    git commit -am "New content"
    new_commit=$(git rev-parse HEAD)
    
    dependency_url="git+file://$PWD"
    
  2. Install the old commit in the consumer.

    cd ../consumer
    npm init -y
    npm config set allow-git=all --location=project
    npm install "dependency@$dependency_url#$old_commit"
    
  3. Change package.json to request the new commit, then run npm install.

    npm pkg set "dependencies.dependency=$dependency_url#$new_commit"
    npm install
    
  4. Check the installed content.

    cat node_modules/dependency/content.txt
    

    Expected: new content
    Actual: old content

    package-lock.json also retains the old commit’s SHA.

Environment
  • npm: 12.0.2 (also reproduced on 11.16.0 and 10.9.8)
  • Node.js: v24.18.0
  • OS Name: LimeOS 0.7.0 (Debian-based, kernel 6.12.94+deb12-amd64)
  • System Model Name: ROG Zephyrus G14 GA403UV_GA403UV 1.0
  • npm config ls:
; "user" config from /home/user/.npmrc

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

; node bin location = /home/user/.nvm/versions/node/v24.18.0/bin/node
; node version = v24.18.0
; npm local prefix = /home/user/Workspace/(redacted)
; npm version = 12.0.2
; cwd = /home/user/Workspace/(redacted)
; HOME = /home/user
; Run `npm config ls -l` to show all defaults.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Run the Bash reproduction using the dependency and consumer directories, then inspect package.json, package-lock.json, and node_modules/dependency. Trace the npm install path that compares the requested Git SHA with the lockfile entry. Done means changing from old_commit to new_commit installs the new content and updates package-lock.json.

Written by the indexing model from the issue text.

Assessment

Tech stack
git, javascript, nodejs
Domain
build-system, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.