Skip to content

[BUG] uninstalling an optional peer dep doesnt remove it #4737

Open
@mohd-akram

Description

@mohd-akram

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

Uninstalling a package does not remove it from the node_modules folder, and does not remove it from package-lock.json.

Expected Behavior

https://docs.npmjs.com/cli/v8/commands/npm-uninstall

This uninstalls a package, completely removing everything npm installed on its behalf.

It also removes the package from the dependencies, devDependencies, optionalDependencies, and peerDependencies objects in your package.json.

Further, if you have an npm-shrinkwrap.json or package-lock.json, npm will update those files as well.

Steps To Reproduce

  1. Run:
mkdir npm-uninstall-test && cd npm-uninstall-test
npm init -y
npm install typeorm sqlite3
npm uninstall sqlite3
[ -e node_modules/sqlite3 ] && echo package still in node_modules
grep -q node_modules/sqlite3 package-lock.json && echo package still in package-lock.json

Environment

  • npm: 8.6.0
  • Node.js: v16.14.0
  • OS Name: Fedora 35
  • System Model Name: HP Laptop
  • npm config:
; "user" config from /home/user/.npmrc

prefix = "/home/user/.local" 

; node bin location = /usr/bin/node
; cwd = /home/user/npm-uninstall-test
; HOME = /home/user
; Run `npm config ls -l` to show all defaults.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Bugthing that needs fixingPriority 2secondary priority issueRelease 8.xwork is associated with a specific npm 8 release

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions