55
votes

Are there simple or subtle reasons that package.json would not update after running a --save-dev? This is my command:

npm install modulename --save-dev

Run from the root of the project. The command succeeds, the new module shows up in the node_modules directory as expected. Help would be appreciated. I am using npm v 1.4.28

The entirety of my current package.json is:

{
    "name": "FooWeb",
    "version": "1.0.0",
    "description": "Foo Web",
    "devDependencies": {
        "gulp": "3.8.11",
        "gulp-jshint": "1.9.2",
        "gulp-concat": "2.5.2",
        "gulp-sass": "1.3.3",
        "gulp-sourcemaps": "1.4.0",
        "gulp-watch": "4.1.1"
    }
}

I do get warnings on install of a package that I have no repository field or README, but I think that is not related.

21
Did you check package.json permissions?Aaron
@Aaron package.json permissions are fine.Brian Muenzenmeyer
didn't know about npm ls pretty neat! in my case it outputs a green extraneous label in the tree for the module, and then errors with ERR! extraneous: [email protected]. [path] I will keep troubleshooting down this path tooBrian Muenzenmeyer
--save worked for me (stackoverflow.com/a/37603531/470749)Ryan
try using cmd and not the vs code terminalSavannah Madison

21 Answers

70
votes

I had this problem as well, and it was driving me crazy.

What finally fixed it was running npm init. This added a bunch of stuff to my package.json, but afterwards --save-dev worked as expected. Even after I removed all the new stuff added by npm init, --save-dev still worked.

13
votes

I had the -g flag there, when I removed it, it worked as expected ...

10
votes

This can occur in VSCode (or probably other editors) if you have an unsaved package.json open.

The file was actually being updated but not reloaded in the IDE. I think maybe the default is to reload only if the file is unedited? Or maybe I clicked something to ignore warnings.

7
votes

navigate to JSON file -> right click properties -> remove "read only" flag.

4
votes

I ran into this recently, and figured out that for whatever reason it was Atom that was preventing the file from updating, even without the file being open.

I closed the editor, re-ran my npm install, opened the editor again and everything was as it should be.

2
votes

Mustafah ELBanna's answer helped me, but i want to expand his answer for other newbies like myself. Please correct me if I miss something important.

If you remove the -g flag, the module is not installed globally for your machine, but only locally in your project. If you also want it to install globally, execute the same command again but now with -g instead of --save-devlike this :

npm install --save-dev [packagename]

npm install -g [packagename]

It seems to me that something might go wrong when calling -g and --save in one line.

But again, I'm new to this and I appreciate anyone who wants to improve/correct my answer.

1
votes

I tried all the commands stated in above answers but got success on installing npm-upgrade package.

npm i -g npm-upgrade then npm-upgrade

1
votes

I was trying to install the gruntjs using "npm install --save grunt-sass" but the package.json won't update

I did everything mentioned above but no luck. But funny thing is if i try adding a package say "underscore (npm install --save underscore)" the son gets updated. I am not sure if this is a problem with the nam as such. I did install as a super user.

1
votes

I faced the same issue because nodemon was already installed globally.

I had to uninstall that first

npm uninstall -g nodemon

Then install it locally as a dev dependency

npm install --save-dev nodemon

The package.json file should then be updated. Sometimes your editor could also prevent the file from updating, so make sure to restart it if does not happen otherwise.

0
votes

There was a syntax error in my package.json that was causing this for me!

0
votes

For me the issue was i copied the command from notepad++ it may have had special chars in there or it was the spaces, and it was not updating my package.json.

e.g. did not work; npm install --save debug pug jwt-simple method-override mongoose

Make sure when you install, you clean up the command line, e.g. any spaces between each module, because there might be special chars in there as well depending on your encoding.

When i corrected it to this it worked.

npm install --save debug pug jwt-simple method-override mongoose

Also, please make sure the package.json isn't opened in an editor when you run the command, because not all editors handle this gracefully.

0
votes

After I used express generator I installed some packages with --s and none of them added to package.json.

Then I deleted the package.json and run npm init and all of them added without having to install again

0
votes

I have an .npmrc file that uses an npm api built in-house to fetch packages. My issue was that I was not connected to my company's VPN.

0
votes

The only way I was able to solve this was by using npm install --save-dev moduleName instead of npm install moduleName --save-dev. Using npm install moduleName --save works fine for me, though. Only when I use --save-dev, I have to put it before the moduleName. I hope this helps anyone.

0
votes

You may first want to check your config (npm config ls command or ~/.npmrc file). I had link=true.

In version 5.5.1, this option seems to be ignored when --save is active. Given that --save-dev supersedes --save, the link mode is active again.

So for me things happens as if --save overrided --link which in turn overrided --save-dev.

0
votes

I had the same problem. When i installed some package, it was not shown on the package.json. So then I deleted the package.json file and ran npm init again. After that it was working and the packages I installed before was also there under dependencies.

0
votes

Removing the dependency from devDependencies in package.json file and installing again using only --save worked for me

0
votes

With the accepted answer still my problem not resolve, then I try to change syntax position Previously I am using the following command to install the module to devDependencies

npm i --save-dev moduleName

Then I toggle the position of moduleName and --save-dev and the moduleName successfully added in the package.json file

npm i moduleName--save-dev

Then the the package.json file updated with the moduleName.

0
votes

This happened to me on Intellij

For anyone else having this issue, did you copy your project from an existing project?

If so, close Intellij and delete the .idea folder. (You can delete node_modules too get a fresh start)

Open the project again and this will be resolved.

0
votes

Just wanted to add another possible answer that proved to be the solution for me.

Verify whether you are in the directory of your angular project. I wasn't and hence the changes were not getting reflected in my package.json file.

0
votes

It can happen if you are not running the command from the package.json directory.

Will happen if you are placed in folder Project instead of Project\ClientApp for example.

You will notice that you only get a package-lock.json in the wrong location if this happens.