npm / npm/cli

[BUG] npm --save-dev does not infer --save

Open
#5,280 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Priority 2 Release 8.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
This issue exists in the latest npm version
  • I am using the latest npm
Current Behavior

When I run npm install --save-dev <package-name> package.json is not modified; nothing is added to devDependencies.

Expected Behavior

I would expect that a command like npm install --save-dev <package-name> would install that package in the current directory and add the package information in package.json's devDepencies object.

Steps To Reproduce
  1. In this environment...
[~/test]$ npm -v
8.15.0
[~/test]$ node -v 
v18.7.0
[~/test]$ sw_vers
ProductName:	macOS
ProductVersion:	12.4
BuildVersion:	21F79
  1. With this config...
$ npm config list
package-lock = false 
save = false 
save-exact = false 
save-prefix = "^" 
  1. Run '...'
[~/test]$ rm -rf package.json 
[~/test]$ rm -rf node_modules 
[~/test]$ npm init -y
Wrote to /Users/matt/test/package.json:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}


[~/test]$ npm install --save-dev mocha

added 79 packages, and audited 80 packages in 6s

20 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
[~/test]$ cat package.json 
{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC"
}
[~/test]$
  1. See error...
    devDependencies does not exist as expected.
Environment
  • npm: 8.15.0
  • Node.js: 18.7.0
  • OS Name: macOS 12.4
  • System Model Name:
  • npm config:
package-lock = false 
save = false 
save-exact = false 
save-prefix = "^" 

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

Reproduce the command using npm 8.15.0, Node.js 18.7.0, and the listed npm configuration, then inspect the generated package.json. Compare the --save-dev result with the expected devDependencies entry; done means a regression test or confirmed behavior clearly covers this case.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.