npm install packagename --save-dev not updating pa

2020-06-30 03:54发布

问题:

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.

回答1:

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.



回答2:

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



回答3:

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



回答4:

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.



回答5:

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.



回答6:

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.



回答7:

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



回答8:

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.



回答9:

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



回答10:

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.



回答11:

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



回答12:

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.



回答13:

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.



回答14:

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.



回答15:

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.



回答16:

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



回答17:

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.



回答18:

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.