npm install is removing scoped packages

cli
help-wanted
priority:medium
triaged

(Armando Altamira) #1

This ticket was already created in github. https://github.com/npm/npm/issues/19527

What I Wanted to Do

When I am installing scoped packages, npm install @my-scope/package npm shouldn’t remove any previously installed packages from the same scope.

What Happened Instead

When I am installing scoped packages, npm install @my-scope/package, npm is removing any previously installed packages from the same scope. All the packages are defined in the package.json as dependencies.

The newly installed (and previously installed) packages remain in the package.json dependencies but the actual directory is removed from node_modules/@my-scope .

Reproduction Steps

Step 1
npm install brentonhouse/npm-defect-test-1

Result

node_modules
   I___ @brentonhouse
                I___ npm-defect-test-1

npm install brentonhouse/npm-defect-test-2

Actual Result:

node_modules
   I___ @brentonhouse
                I___ npm-defect-test-2

Expected Result:

node_modules
   I___ @brentonhouse
                I___ npm-defect-test-1
                I___ npm-defect-test-2

Details

If I run npm install (with no other parameters), it will install all the scoped packages from github fine. (because they exist in the package.json dependencies section)

Platform Info

$ npm --versions
{ npm: '5.8.0',
  ares: '1.10.1-DEV',
  cldr: '31.0.1',
  http_parser: '2.7.0',
  icu: '59.1',
  modules: '57',
  nghttp2: '1.25.0',
  node: '8.9.4',
  openssl: '1.0.2n',
  tz: '2017b',
  unicode: '9.0',
  uv: '1.15.0',
  v8: '6.1.534.50',
  zlib: '1.2.11' }
$ node -p process.platform
darwin

(Lars Willighagen) #2

Can’t reproduce this, does it work for you on npm v6.4.1?

$ npm ini -y
Wrote to /.../Testing/npm.community/067/package.json:

{
  "name": "067",
  "version": "1.0.0",
  "description": "https://npm.community/t/npm-install-is-removing-scoped-packages/3399",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


$ npm i brentonhouse/npm-defect-test-1
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN 067@1.0.0 No repository field.

+ @myscope/test1@1.0.0
added 1 package and audited 1 package in 1.886s
found 0 vulnerabilities

$ npm i brentonhouse/npm-defect-test-2
npm WARN 067@1.0.0 No repository field.

+ @myscope/test2@1.0.0
added 1 package and audited 2 packages in 1.88s
found 0 vulnerabilities

$ tree node_modules/
node_modules/
└── @myscope
    ├── test1
    │   └── package.json
    └── test2
        └── package.json

3 directories, 2 files

(Darryl Pogue) #3

The behaviour here seems similar to what I’m seeing in `npm install` (via Cordova) removing everything in node_modules but it’s hard to tell without any verbose logging output.