node.js npm install packagename --save-dev 不更新 package.json

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30079558/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 18:44:08  来源:igfitidea点击:

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

node.jsdependenciesnpm

提问by Brian Muenzenmeyer

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

是否有简单或微妙的原因package.json在运行 --save-dev 后不会更新?这是我的命令:

npm install modulename --save-dev

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

从项目的根运行。命令成功,新模块按预期显示在 node_modules 目录中。帮助将不胜感激。我正在使用 npm v 1.4.28

The entirety of my current package.jsonis:

我目前的全部情况package.json是:

{
    "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.

我确实在安装没有存储库字段或自述文件的软件包时收到警告,但我认为这不相关。

回答by hook

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-devworked as expected. Even after I removed all the new stuff added by npm init, --save-devstill worked.

最终修复它的是运行npm init。这在我的 package.json 中添加了一堆东西,但后来--save-dev按预期工作。即使在我删除了添加的所有新内容之后npm init--save-dev仍然有效。

回答by Mustafah

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

我在那里有 -g 标志,当我删除它时,它按预期工作......

回答by ndesign11

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

导航到 JSON 文件 -> 右键单击​​属性 -> 删除“只读”标志。

回答by Simon_Weaver

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

如果您package.json打开了未保存的文件,这可能会发生在 VSCode(或可能是其他编辑器)中。

The file wasactually 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.

该文件实际被更新,但在IDE中没有重新加载。我想也许默认值是仅在文件未编辑时重新加载?或者也许我点击了一些东西来忽略警告。

回答by Phil Mayfield

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.

我最近遇到了这个问题,并发现无论出于何种原因,即使文件没有打开,也是 Atom 阻止了文件更新。

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

我关闭了编辑器,重新运行我的 npm 安装,再次打开编辑器,一切都应该如此。

回答by Kenny

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.

Mustafah ELBanna 的回答对我有所帮助,但我想为像我这样的其他新手扩展他的回答。如果我错过了重要的事情,请纠正我。

If you remove the -gflag, 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 -ginstead of --save-devlike this :

如果您删除该-g标志,则该模块不会在您的机器上全局安装,而只会在您的项目中本地安装。如果您还希望它全局安装,请再次执行相同的命令,但现在使用-g而不是--save-dev这样:

npm install --save-dev [packagename]

npm install --save-dev [packagename]

npm install -g [packagename]

npm install -g [packagename]

It seems to me that something might go wrong when calling -gand --savein one line.

在我看来,呼叫-g--save一行时可能会出现问题。

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

但同样,我是新手,我感谢任何想要改进/纠正我的答案的人。

回答by Kanishk Gupta

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

我尝试了上述答案中所述的所有命令,但在安装npm-upgrade软件包方面取得了成功。

npm i -g npm-upgradethen npm-upgrade

npm i -g npm-upgrade然后 npm-upgrade

回答by Yoosaf Abdulla

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

我试图使用“npm install --save grunt-sass”安装 gruntjs,但 package.json 不会更新

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.

我做了上面提到的一切,但没有运气。但有趣的是,如果我尝试添加一个包,说“下划线(npm install --save underscore)”,儿子就会更新。我不确定这是否是 nam 本身的问题。我确实以超级用户身份安装。

回答by RockyRoad

You may first want to check your config (npm config lscommand or ~/.npmrcfile). I had link=true.

您可能首先要检查您的配置(npm config ls命令或~/.npmrc文件)。我有link=true

In version 5.5.1, this option seems to be ignored when --saveis active. Given that --save-devsupersedes --save, the link modeis active again.

在 5.5.1 版本中,当--save处于活动状态时,此选项似乎被忽略。鉴于--save-dev取代--save链接模式再次处于活动状态。

So for me things happens as if --saveoverrided --linkwhich in turn overrided --save-dev.

所以对我来说,事情好像被--save覆盖了--link,然后又被覆盖了--save-dev

回答by dilanSachi

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.

我有同样的问题。当我安装一些包时,它没有显示在 package.json 上。然后我删除了 package.json 文件并再次运行 npm init 。之后它就可以工作了,我之前安装的软件包也在依赖项下。