npm / npm/cli

[BUG] v7 erroneously reports removal of packages

Open
#3,574 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 7.x
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
Current Behavior

After installing aws-cdk package, subsequent npm commands such as install, prune, etc. always report "removed 7 packages" and the following lines:

npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/yallist
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/semver
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/lru-cache
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/yallist
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/semver
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/lru-cache
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/jsonschema

All of the above directories still exist after each command, so they are not actually deleted.

This bug appears to have been introduced in v7.0.0 as it occurs in v7.20.1, v7.0.0, but not in v6.14.13.

Expected Behavior

No packages were removed and npm should report as such.

Steps To Reproduce
mkdir v6
cd v6
npx npm@6 --version         # 6.14.13
npx npm@6 i aws-cdk@1.115.0 # added 181 packages from 216 contributors and audited 181 packages in 2.724s
stat node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/yallist # does not exist
npx npm@6 i --ddd           # audited 181 packages in 1.039s
stat node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/yallist # does not exist
npx npm@6 i --ddd           # audited 181 packages in 0.944s
npx npm@6 prune -ddd        # audited 181 packages in 0.897s
npx npm@6 prune -ddd        # audited 181 packages in 1.008s

cd ..
mkdir v7
cd v7
npx npm@7 i --version       # 7.20.1
npx npm@7 i aws-cdk@1.115.0 # added 181 packages, and audited 182 packages in 2s
stat node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/yallist # exists
npx npm@7 i --ddd           # removed 7 packages, and audited 182 packages in 734ms
stat node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/yallist # exists
npx npm@7 i --ddd           # removed 7 packages, and audited 182 packages in 728ms
npx npm@7 prune --ddd       # removed 7 packages, and audited 182 packages in 699ms
npx npm@7 prune --ddd       # removed 7 packages, and audited 182 packages in 1s

Notice the output for all but the first npm commands report "removed 7 packages" for v7 but not for v6. Also, the following lines:

npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/yallist
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/semver
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cx-api/node_modules/lru-cache
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/yallist
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/semver
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/lru-cache
npm sill REMOVE node_modules/aws-cdk/node_modules/@aws-cdk/cloud-assembly-schema/node_modules/jsonschema

Notice these reported directories were never created in v6, and in v7 they are never deleted (still exist every v7 npm command) despite being reported as "REMOVE".

Attached the output for the first 3 install commands and the package files for v7:
1.log
2.log
3.log
package.json.txt
package-lock.json.txt

Environment
  • OS: Ubuntu 18.04.3 LTS (WSL2)
  • Node: v14.17.0
  • npm: 7.20.1

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

Start by reproducing the v7 behavior with the commands in the issue, comparing it with npm 6 and reviewing 1.log, 2.log, 3.log, package.json.txt, and package-lock.json.txt. Trace the reported REMOVE entries and verify with repeated install and prune runs that the output no longer claims packages were removed when their directories remain.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
cli, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.