gpt4 book ai didi

npm - 如何更新 package-lock.json 中的一个包的依赖

转载 作者:行者123 更新时间:2023-12-04 17:37:14 24 4
gpt4 key购买 nike

我们想将 lodash 版本更新到 4.17.11,但它是 grunt-angular-translate 的依赖项。 grunt-angular-translate 在 package.json 中。如果我将 grunt-angular-translate 更新到 0.3.0,它不会将 lodash 更新到版本 4.7.11。我们如何更新 package-lock.json 中的依赖项。

package.json:

"devDependencies": {
"grunt": "^1.0.3",
"grunt-angular-translate": "^1.0.0",
"grunt-bump": "^0.8.0",

包锁.json:

"grunt-angular-translate": {
"version": "0.3.0",
"resolved": "https://registry.npmjs.org/grunt-angular-translate/-/grunt-angular-translate-0.3.0.tgz",
"integrity": "sha1-vQEYr6JNj1cCMf2NUtgp2AjFEbM=",
"dev": true,
"requires": {
"flat": "^1.2.0",
"json-stable-stringify": "^1.0.0",
"lodash": "~2.4.1"
},
"dependencies": {
"lodash": {
"version": "2.4.2",
"resolved": "https://registry.npmjs.org/lodash/-/lodash-2.4.2.tgz",
"integrity": "sha1-+t2DS5aDBz2hebPq5tnA0VBT9z4=",
"dev": true
}
}
},

最佳答案

根据 npm docs :

package-lock.json is automatically generated for any operations where npm modifies either the node_modules tree, or package.json. It describes the exact tree that was generated, such that subsequent installs are able to generate identical trees, regardless of intermediate dependency updates.

This file is intended to be committed into source repositories, and serves various purposes:

Describe a single representation of a dependency tree such that teammates, deployments, and continuous integration are guaranteed to install exactly the same dependencies.

Provide a facility for users to “time-travel” to previous states of node_modules without having to commit the directory itself.

To facilitate greater visibility of tree changes through readable source control diffs.

And optimize the installation process by allowing npm to skip repeated metadata resolutions for previously-installed packages.

package.json 中,您可以指定您在应用中使用的 npm 包。换句话说,你有一个特定的依赖关系,所以你的包可以运行。

package-lock.json您的应用程序使用它们的依赖项 的每个包的大“ map ”,您不能影响。

在你的例子中,grunt-angular-translate"lodash": "~2.4.1"它自己的依赖,你可以不要更改它,也不应尝试更改它,因为该软件包应该与该版本一起使用,而不是与可能存在大量重大更改的 2 个版本更高的软件包一起使用。

您可以将 lodash 的直接依赖项升级到其最新版本,但这不会将 grunt-angular-translate 对 lodash 的依赖项更新到该版本,它确实不应该。

真正应该发生的是在您的 node_modules 文件夹中,您将获得更新的 lodash(您可以通过查看它的 package.json 和里面的版本来检查)。在同一个文件夹中,如果你进入 grunt-angular-translate 文件夹并查看它自己的 node_modules ...它应该有自己的 lodash 文件夹和 lodash 2.4.1在里面。

关于npm - 如何更新 package-lock.json 中的一个包的依赖,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56150065/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com