npm install packagename --save-dev not updating package.json

node.jsDependenciesNpm

node.js Problem Overview


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.

node.js Solutions


Solution 1 - node.js

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.

Solution 2 - node.js

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

Solution 3 - node.js

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.

Solution 4 - node.js

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

Solution 5 - node.js

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.

Solution 6 - node.js

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.

Solution 7 - node.js

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.

Solution 8 - node.js

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

Solution 9 - node.js

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.

Solution 10 - node.js

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

Solution 11 - node.js

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.

Solution 12 - node.js

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

Solution 13 - node.js

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.

Solution 14 - node.js

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.

Solution 15 - node.js

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.

Solution 16 - node.js

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.

Solution 17 - node.js

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

Solution 18 - node.js

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.

Solution 19 - node.js

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.

Solution 20 - node.js

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.

Solution 21 - node.js

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBrian MuenzenmeyerView Question on Stackoverflow
Solution 1 - node.jshookView Answer on Stackoverflow
Solution 2 - node.jsMustafahView Answer on Stackoverflow
Solution 3 - node.jsSimon_WeaverView Answer on Stackoverflow
Solution 4 - node.jsndesign11View Answer on Stackoverflow
Solution 5 - node.jsPhil MayfieldView Answer on Stackoverflow
Solution 6 - node.jsKennyView Answer on Stackoverflow
Solution 7 - node.jsShayanView Answer on Stackoverflow
Solution 8 - node.jsKanishk GuptaView Answer on Stackoverflow
Solution 9 - node.jsYoosaf AbdullaView Answer on Stackoverflow
Solution 10 - node.jsJason DorellView Answer on Stackoverflow
Solution 11 - node.jsblambView Answer on Stackoverflow
Solution 12 - node.jskochavView Answer on Stackoverflow
Solution 13 - node.jskoolkatView Answer on Stackoverflow
Solution 14 - node.jsM.Z.View Answer on Stackoverflow
Solution 15 - node.jsRockyRoadView Answer on Stackoverflow
Solution 16 - node.jsdilanSachiView Answer on Stackoverflow
Solution 17 - node.jsRahul MakhijaView Answer on Stackoverflow
Solution 18 - node.jsVIKAS KOHLIView Answer on Stackoverflow
Solution 19 - node.jsOjonugwa Jude OchalifuView Answer on Stackoverflow
Solution 20 - node.jsTejas JaggiView Answer on Stackoverflow
Solution 21 - node.jsOgglasView Answer on Stackoverflow