[英]How to update each dependency in package.json to the latest version?
I copied package.json
from another project and now want to bump all of the dependencies to their latest versions since this is a fresh project and I don't mind fixing something if it breaks.我从另一个项目复制package.json
,现在想将所有依赖项升级到最新版本,因为这是一个新项目,如果它坏了我不介意修复它。
What's the easiest way to do this?最简单的方法是什么?
The best way I know is to run npm info express version
then update each dependency in package.json
manually.我知道的最好方法是运行npm info express version
,然后手动更新package.json
中的每个依赖项。 There must be a better way.一定会有更好的办法。
{
"name": "myproject",
"description": "my node project",
"version": "1.0.0",
"engines": {
"node": "0.8.4",
"npm": "1.1.65"
},
"private": true,
"dependencies": {
"express": "~3.0.3", // how do I get these bumped to latest?
"mongodb": "~1.2.5",
"underscore": "~1.4.2",
"rjs": "~2.9.0",
"jade": "~0.27.2",
"async": "~0.1.22"
}
}
For Yarn specific solutions refer to this Stack Overflow thread.对于Yarn特定的解决方案,请参阅此 Stack Overflow线程。
Looks like npm-check-updates is the only way to make this happen now.看起来npm-check-updates是现在实现这一点的唯一方法。
npm i -g npm-check-updates
ncu -u
npm install
On npm <3.11:在 npm <3.11 上:
Simply change every dependency's version to *
, then run npm update --save
.只需将每个依赖项的版本更改为*
,然后运行npm update --save
。 ( Note: broken in recent (3.11) versions of npm ). (注意:在最近(3.11)版本的 npm 中损坏)。
Before:前:
"dependencies": {
"express": "*",
"mongodb": "*",
"underscore": "*",
"rjs": "*",
"jade": "*",
"async": "*"
}
After:后:
"dependencies": {
"express": "~3.2.0",
"mongodb": "~1.2.14",
"underscore": "~1.4.4",
"rjs": "~2.10.0",
"jade": "~0.29.0",
"async": "~0.2.7"
}
Of course, this is the blunt hammer of updating dependencies.当然,这是更新依赖的钝锤。 It's fine if—as you said—the project is empty and nothing can break.如果——正如你所说——项目是空的并且没有什么可以破坏,那很好。
On the other hand, if you're working in a more mature project, you probably want to verify that there are no breaking changes in your dependencies before upgrading.另一方面,如果您在一个更成熟的项目中工作,您可能希望在升级之前验证您的依赖项中没有重大更改。
To see which modules are outdated, just run npm outdated
.要查看哪些模块已过时,只需运行npm outdated
。 It will list any installed dependencies that have newer versions available.它将列出所有已安装的具有较新版本的依赖项。
For Yarn specific solution, refer to this StackOverflow answer .对于Yarn特定的解决方案,请参阅此 StackOverflow 答案。
npm-check-updates
is a utility that automatically adjusts a package.json with the latest version of all dependencies npm-check-updates
是一个实用程序,它使用所有依赖项的最新版本自动调整 package.json
see https://www.npmjs.org/package/npm-check-updates见https://www.npmjs.org/package/npm-check-updates
$ npm install -g npm-check-updates
$ ncu -u
$ npm install
[EDIT] A slightly less intrusive (avoids a global install) way of doing this if you have a modern version of npm
is: [编辑] 如果您有现代版本的npm
,那么一种稍微不那么侵入性(避免全局安装)的方法是:
$ npx npm-check-updates -u
$ npm install
npm outdated
npm update
git commit package-lock.json
npm install -g npm-check-updates
npm-check-updates
npm shrinkwrap
git commit package-lock.json
Be sure to shrinkwrap your deps, or you may wind up with a dead project.一定要收缩你的部门,否则你可能会得到一个死项目。 I pulled out a project the other day and it wouldn't run because my deps were all out of date/updated/a mess.前几天我退出了一个项目,但它无法运行,因为我的部门都已过时/更新/一团糟。 If I'd shrinkwrapped, npm would have installed exactly what I needed.如果我收缩包装,npm 会完全安装我需要的东西。
For the curious who make it this far, here is what I recommend:对于能走到这一步的好奇者,我推荐以下内容:
npm-check-updates
or npm outdated
to suggest the latest versions.使用npm-check-updates
或npm outdated
建议最新版本。# `outdated` is part of newer npm versions (2+)
$ npm outdated
# If you agree, update.
$ npm update
# OR
# Install and use the `npm-check-updates` package.
$ npm install -g npm-check-updates
# Then check your project
$ npm-check-updates
# If you agree, update package.json.
$ npm-check-updates -u
###Then do a clean install (w/o the rm I got some dependency warnings) ###然后进行全新安装(没有 rm 我收到了一些依赖警告)
$ rm -rf node_modules
$ npm install
npm-shrinkwrap.json
with npm shrinkwrap
最后,使用 npm shrinkwrap 将确切的版本保存到npm-shrinkwrap.json
npm shrinkwrap
$ rm npm-shrinkwrap.json
$ npm shrinkwrap
npm install
will now use exact versions in npm-shrinkwrap.json
现在, npm install
现在将使用npm-shrinkwrap.json
中的确切版本If you check npm-shrinkwrap.json
into git, all installs will use the exact same versions.如果您将npm-shrinkwrap.json
检入 git,所有安装都将使用完全相同的版本。
This is a way to transition out of development (all updates, all the time) to production (nobody touch nothing).这是一种从开发(所有更新,一直)过渡到生产(没有人什么都不做)的方法。
ps Yarn is sending your package list to Facebook . ps Yarn 正在将您的包裹清单发送到 Facebook 。
To update one dependency to its lastest version without having to manually open the package.json
and change it, you can run要将一个依赖项更新到其最新版本而无需手动打开package.json
并更改它,您可以运行
npm install {package-name}@* {save flags?}
ie IE
npm install express@* --save
This flow is compatible with workspaces, ie此流程与工作空间兼容,即
npm --workspace some/package install express@*
For reference, npm-install作为参考, npm-install
Note : Some npm versions may need latest flag instead, ie npm install express@latest
注意:某些 npm 版本可能需要latest标志,即npm install express@latest
As noted by user Vespakoen on a rejected edit, it's also possible to update multiple packages at once this way:正如用户Vespakoen在被拒绝的编辑中指出的那样,也可以通过这种方式一次更新多个包:
npm install --save package-nave@* other-package@* whatever-thing@*
He also apports a one-liner for the shell based on npm outdated
.他还为基于npm outdated
的 shell 提供了一个单行代码。 See the edit for code and explanation.请参阅编辑以获取代码和解释。
PS: I also hate having to manually edit package.json
for things like that ;) PS:我也讨厌必须手动编辑package.json
类的东西;)
If you happen to be using Visual Studio Code as your IDE, this is a fun little extension to make updating package.json
a one click process.如果您碰巧使用Visual Studio Code作为您的 IDE,这是一个有趣的小扩展,可以让更新package.json
成为一个单击过程。
This works as of npm 1.3.15.这适用于 npm 1.3.15。
"dependencies": {
"foo": "latest"
}
*
as the version for the latest releases, including unstable使用*
作为最新版本的版本,包括不稳定的latest
as version definition for the latest stable version使用latest
作为最新稳定版本的版本定义LatestStablePackages
使用LatestStablePackages
使用最新的稳定版本号修改 package.jsonHere is an example:这是一个例子:
"dependencies": {
"express": "latest" // using the latest STABLE version
, "node-gyp": "latest"
, "jade": "latest"
, "mongoose": "*" // using the newest version, may involve the unstable releases
, "cookie-parser": "latest"
, "express-session": "latest"
, "body-parser": "latest"
, "nodemailer":"latest"
, "validator": "latest"
, "bcrypt": "latest"
, "formidable": "latest"
, "path": "latest"
, "fs-extra": "latest"
, "moment": "latest"
, "express-device": "latest"
},
To see which packages have newer versions available, then use the following command:要查看哪些软件包有较新的版本可用,请使用以下命令:
npm outdated
to update just one dependency just use the following command:要仅更新一个依赖项,只需使用以下命令:
npm install yourPackage@latest
For example:例如:
My package.json
file has dependency:我的package.json
文件具有依赖性:
"@progress/kendo-angular-dateinputs": "^1.3.1",
then I should write:那么我应该写:
npm install @progress/kendo-angular-dateinputs@latest
What does --save-dev
mean? --save-dev
是什么意思?
npm install @progress/kendo-angular-dateinputs@latest --save-dev
As npm install docs says:正如 npm install docs 所说:
-D, --save-dev: Package will appear in your devDependencies. -D, --save-dev:包会出现在你的devDependencies中。
The only caveat I have found with the best answer above is that it updates the modules to the latest version.我发现上面最好的答案的唯一警告是它将模块更新到最新版本。 This means it could update to an unstable alpha build.这意味着它可以更新为不稳定的 alpha 版本。
I would use that npm-check-updates utility.我会使用那个 npm-check-updates 实用程序。 My group used this tool and it worked effectively by installing the stable updates.我的小组使用了这个工具,它通过安装稳定的更新有效地工作。
As Etienne stated above: install and run with this:正如 Etienne 上面所说:安装和运行这个:
$ npm install -g npm-check-updates
$ npm-check-updates -u
$ npm install
I really like how npm-upgrade works.我真的很喜欢npm-upgrade 的工作方式。 It is a simple command line utility that goes through all of your dependencies and lets you see the current version compared to the latest version and update if you want.它是一个简单的命令行实用程序,它遍历所有依赖项,让您查看当前版本与最新版本的比较,并根据需要进行更新。
Here is a screenshot of what happens after running npm-upgrade
in the root of your project (next to the package.json
file):这是在项目的根目录(在package.json
文件旁边)运行npm-upgrade
后发生的屏幕截图:
For each dependency you can choose to upgrade, ignore, view the changelog, or finish the process.对于每个依赖项,您可以选择升级、忽略、查看更改日志或完成该过程。 It has worked great for me so far.到目前为止,它对我来说效果很好。
To be clear this is a third party package that needs to be installed before the command will work.需要明确的是,这是一个第三方包,需要在命令生效之前安装。 It does not come with npm itself:它不附带 npm 本身:
npm install -g npm-upgrade
Then from the root of a project that has a package.json file:然后从具有 package.json 文件的项目的根目录:
npm-upgrade
Here is a basic regex to match semantic version numbers so you can quickly replace them all with an asterisk.这是一个匹配语义版本号的基本正则表达式,因此您可以用星号快速替换它们。
([>|<|=|~|^|\s])*?(\d+\.)?(\d+\.)?(\*|\d+)
Select the package versions you want to replace in the JSON file.在 JSON 文件中选择要替换的包版本。
Input the regex above and verify it's matching the correct text.输入上面的正则表达式并验证它是否匹配正确的文本。
Replace all matches with an asterisk.用星号替换所有匹配项。
Run npm update --save
运行npm update --save
If you want to use a gentle approach via a beautiful (for terminal) interactive reporting interface I would suggest using npm-check .如果您想通过漂亮的(终端)交互式报告界面使用温和的方法,我建议使用npm-check 。
It's less of a hammer and gives you more consequential knowledge of, and control over, your dependency updates.它不像一把锤子,让您对依赖项更新有更多的相关知识和控制权。
To give you a taste of what awaits here's a screenshot (scraped from the git page for npm-check):为了让您了解等待这里的内容,这里有一个屏幕截图(从 npm-check 的 git 页面中抓取):
This feature has been introduced in npm v5
.此功能已在npm v5
中引入。 update to npm using npm install -g npm@latest
and使用npm install -g npm@latest
更新到 npm 和
to update package.json
更新package.json
delete /node_modules
and package-lock.json (if you have any)
删除/node_modules
和package-lock.json (if you have any)
run npm update
.运行npm update
。 this will update the dependencies package.json to the latest, based on semver .这将根据semver将依赖项 package.json 更新到最新版本。
to update to very latest version.更新到最新版本。 you can go with npm-check-updates
您可以使用npm-check-updates
I recently had to update several projects that were using npm and package.json for their gruntfile.js magic.我最近不得不更新几个使用 npm 和 package.json 来实现 gruntfile.js 魔法的项目。 The following bash command (multiline command) worked well for me:以下 bash 命令(多行命令)对我来说效果很好:
npm outdated --json --depth=0 | \
jq --ascii-output --monochrome-output '. | keys | .[]' | \
xargs npm install $1 --save-dev
The idea here: To pipe the npm outdated
output as json, to jq
这里的想法:将npm outdated
的输出作为 json 管道传输到jq
(jq is a json command line parser/query tool) (jq 是一个 json 命令行解析器/查询工具)
(notice the use of --depth
argument for npm outdated
) (注意npm outdated
使用--depth
参数)
jq will strip the output down to just the top level package name only. jq 会将输出剥离到仅顶级包名称。
finally xargs puts each LIBRARYNAME one at a time into a npm install LIBRARYNAME --save-dev
command最后 xargs 一次将每个 LIBRARYNAME 放入npm install LIBRARYNAME --save-dev
命令
The above is what worked for me on a machine runnning: node=v0.11.10 osx=10.9.2 npm=1.3.24以上是在运行的机器上对我有用的: node=v0.11.10 osx=10.9.2 npm=1.3.24
this required:这需要:
xargs http://en.wikipedia.org/wiki/Xargs (native to my machine I believe) xargs http://en.wikipedia.org/wiki/Xargs (我相信我的机器原生)
and和
jq http://stedolan.github.io/jq/ (I installed it with brew install jq
) jq http://stedolan.github.io/jq/ (我用brew install jq
安装了它)
Note: I only save the updated libraries to package.json inside of the json key devDependancies
by using --save-dev
, that was a requirement of my projects, quite possible not yours.注意:我只使用--save-dev
将更新的库保存到 json 键devDependancies
内的 package.json 中,这是我的项目的要求,很可能不是你的。
Afterward I check that everything is gravy with a simple之后我用一个简单的方法检查所有东西都是肉汁
npm outdated --depth=0
Also, you can check the current toplevel installed library versions with此外,您可以检查当前顶级安装的库版本
npm list --depth=0
As of npm version 5.2.0, there is a way to run this in a single line without installing any additional packages to your global npm registry nor locally to your application.从 npm 版本 5.2.0 开始,有一种方法可以在一行中运行它,而无需在全局 npm 注册表或本地应用程序中安装任何额外的包。 This can be done by leveraging the new npx
utility that's bundled with npm.这可以通过利用与 npm 捆绑在一起的新npx
实用程序来完成。 ( Click here to learn more. ) ( 点击这里了解更多。 )
Run the following command in the root of your project:在项目的根目录中运行以下命令:
npx npm-check-updates -u && npm i
I use npm-check
to achieve this.我使用npm-check
来实现这一点。
npm i -g npm npm-check
npm-check -ug #to update globals
npm-check -u #to update locals
Another useful command list which will keep exact version numbers in package.json
另一个有用的命令列表,它将在package.json
中保留准确的版本号
npm cache clean
rm -rf node_modules/
npm i -g npm npm-check-updates
ncu -g #update globals
ncu -ua #update locals
npm I
Update: You can use yarn upgrade-interactive --latest
if you are using yarn
更新:如果您使用的是 yarn,您可以使用yarn
yarn upgrade-interactive --latest
If you use yarn, the following command updates all packages to their latest version:如果您使用 yarn,以下命令会将所有包更新到最新版本:
yarn upgrade --latest
The
upgrade --latest
command upgrades packages the same as the upgrade command, but ignores the version range specified in package.json.upgrade --latest
命令升级包与升级命令相同,但忽略 package.json 中指定的版本范围。 Instead, the version specified by the latest tag will be used (potentially upgrading the packages across major versions).相反,将使用由 latest 标签指定的版本(可能跨主要版本升级包)。
Updtr!更新!
Based on npm outdated, updtr installs the latest version and runs npm test for each dependency.基于 npm outdated,updtr 安装最新版本并为每个依赖项运行 npm test。 If the test succeeds, updtr saves the new version number to your package.json.如果测试成功,updtr 会将新版本号保存到您的 package.json 中。 If the test fails, however, updtr rolls back its changes.但是,如果测试失败,updtr 将回滚其更改。
https://github.com/peerigon/updtr https://github.com/peerigon/updtr
Safe update安全更新
Use 'npm outdated' to discover dependencies that are out of date.使用“npm outdated”来发现过期的依赖项。
Use 'npm update' to perform safe dependency upgrades.使用“npm update”来执行安全的依赖升级。
Use 'npm install @latest' to upgrade to the latest major version of a package.使用 'npm install @latest' 升级到软件包的最新主要版本。
Breaking Update重大更新
Use 'npx npm-check-updates -u'.使用“npx npm-check-updates -u”。
'npm install' to upgrade all dependencies to their latest major versions. 'npm install' 将所有依赖项升级到最新的主要版本。
If you are using yarn
,yarn upgrade-interactive
is a really sleek tool that can allow you to view your outdated dependencies and then select which ones you want to update.如果您使用的是yarn
,yarn upgrade-interactive
是一个非常时尚的工具,可以让您查看过时的依赖项,然后选择要更新的依赖项。
More reasons to use Yarn over npm
.在npm
上使用 Yarn 的更多理由。 Heh.呵呵。
Commands that I had to use to update package.json
for NPM 3.10.10
:我必须用来为NPM 3.10.10
更新package.json
的命令:
npm install -g npm-check-updates
ncu -a
npm install
Background:背景:
I was using the latest command from @josh3736 but my package.json
was not updated.我正在使用来自 @josh3736 的最新命令,但我的package.json
没有更新。 I then noticed the description text when running npm-check-updates -u
:然后我在运行npm-check-updates -u
时注意到了描述文本:
The following dependency is satisfied by its declared version range, but the installed version is behind.其声明的版本范围满足以下依赖关系,但安装的版本落后。 You can install the latest version without modifying your package file by using npm update.您可以使用 npm update 安装最新版本,而无需修改包文件。 If you want to update the dependency in your package file anyway, run ncu -a.如果您仍然想更新包文件中的依赖项,请运行 ncu -a。
Reading the documentation for npm-check-updates you can see the difference:阅读 npm-check-updates 的文档,您可以看到不同之处:
https://www.npmjs.com/package/npm-check-updates https://www.npmjs.com/package/npm-check-updates
-u, --upgrade: overwrite package file -u, --upgrade:覆盖包文件
-a, --upgradeAll: include even those dependencies whose latest version satisfies the declared semver dependency -a, --upgradeAll:甚至包括那些最新版本满足声明的semver依赖的依赖
ncu is an alias for npm-check-updates
as seen in the message when typing npm-check-updates -u
: ncu 是npm-check-updates
的别名,如键入npm-check-updates -u
时在消息中所示:
[INFO]: You can also use ncu as an alias
如果你不想安装全局npm-check-updates你可以简单地运行:
node -e "const pk = JSON.parse(require('fs').readFileSync('package.json', 'utf-8'));require('child_process').spawn('npm', ['install', ...Object.keys(Object.assign({},pk.dependencies, pk.devDependencies)).map(a=>a+'@latest')]).stdout.on('data', d=>console.log(d.toString()))"
The above commands are unsafe because you might break your module when switching versions.上面的命令是不安全的,因为你可能会在切换版本时破坏你的模块。 Instead I recommend the following相反,我推荐以下
npm shrinkwrap
command.使用npm shrinkwrap
命令将实际的当前节点模块版本设置为 package.json。npm install -g next-update // from your package next-update
Try following command if you using npm 5 and node 8如果您使用 npm 5 和节点 8,请尝试以下命令
npm update --save npm 更新--保存
I found another solution for recent version of NPM.我为最新版本的 NPM 找到了另一个解决方案。 What I want to do is to replace all the "*" dependencies with the explicit lastest version number.我想要做的是用明确的最新版本号替换所有“*”依赖项。 None of the methods discussed has worked for me.所讨论的方法都不适合我。
What I did:我做了什么:
npm-check-updates -u
运行npm-check-updates -u
Everything in package.json now is updated to the last version. package.json 中的所有内容现在都更新到了最新版本。
If you're looking for an easier solution that doesn't involve installing npm packages, I'd checkout updatepackagejson.com如果您正在寻找不涉及安装 npm 包的更简单的解决方案,我会查看updatepackagejson.com
The following code (which was accepted) wrote me something like "it takes too long blah-blah" and did nothing.以下代码(已被接受)给我写了“它需要太长时间等等”之类的东西,但什么也没做。 Probably using the global flag was the problem, idk.可能使用全局标志是问题,idk。
npm i -g npm-check-updates
ncu -u
npm install
I decided to use my text editor and follow a semi-manual approach instead.我决定使用我的文本编辑器并遵循半手动方法。
I copied a list like this (just a lot longer) from the dev dependencies of my package.json
to the notepad++ text editor:我从我的package.json
的开发依赖项中复制了一个这样的列表(只是更长的时间)到 notepad++ 文本编辑器:
"browserify": "10.2.6",
"expect.js": "^0.3.1",
"karma": "^0.13.22",
"karma-browserify": "^5.2.0",
I set the search mode to regular expression, used the ^\s*"([^"]+)".*$
pattern to get the package name and replaced it with npm uninstall \1 --save-dev \nnpm install \1 --save-dev
. Clicked on "replace all". The otput was this:我将搜索模式设置为正则表达式,使用^\s*"([^"]+)".*$
模式获取包名称并将其替换为npm uninstall \1 --save-dev \nnpm install \1 --save-dev
。点击“全部替换”。输出是这样的:
npm uninstall browserify --save-dev
npm install browserify --save-dev
npm uninstall expect.js --save-dev
npm install expect.js --save-dev
npm uninstall karma --save-dev
npm install karma --save-dev
npm uninstall karma-browserify --save-dev
npm install karma-browserify --save-dev
I copied it back to bash and hit enter.我将它复制回 bash 并按回车键。 Everything was upgraded and working fine.一切都升级了,工作正常。 That's all.就这样。
"browserify": "^16.1.0",
"expect.js": "^0.3.1",
"karma": "^2.0.0",
"karma-browserify": "^5.2.0",
I don't think it is a big deal, since you have to do it only every now and then, but you can easily write a script, which parses the package.json
and upgrades your packages.我认为这没什么大不了的,因为您只需要时不时地这样做,但是您可以轻松编写一个脚本来解析package.json
并升级您的包。 I think it is better this way, because you can edit your list if you need something special, for example keeping the current version of a lib.我认为这种方式更好,因为如果你需要一些特殊的东西,你可以编辑你的列表,例如保留当前版本的 lib。
I solved this by seeing the instructions from https://github.com/tjunnone/npm-check-updates我通过查看https://github.com/tjunnone/npm-check-updates的说明解决了这个问题
$ npm install -g npm-check-updates
$ ncu
$ ncu -u # to update all the dependencies to latest
$ ncu -u "specific module name" #in case you want to update specific dependencies to latest
As it's almost 10 years since the original question, many of the answers are either outdated or not recommended.由于距离最初的问题已经过去将近 10 年,因此许多答案要么已过时,要么不推荐。
I would use something which is package manager agnostic ie can work with npm, pnpm, yarn or others.我会使用与 package 管理器无关的东西,即可以与 npm、pnpm、yarn 或其他一起使用。
Lately I have been using taze最近一直在用taze
You can either add it to your dev dependencies and run from there or run without installation with npx taze
or pnpx taze
, etc.您可以将它添加到您的开发依赖项并从那里运行,或者在不安装 npx npx taze
或pnpx taze
等的情况下运行。
It's wild to me that 90% of answers is some variant of "use npm-check-updates
". 90% 的答案都是“使用npm-check-updates
”的变体,这对我来说很疯狂。 Here's what I do (relevant code):这是我所做的(相关代码):
{
"devDependencies": {
"updates": "^13.0.5" // the version here could be "latest" or "*" tbh...
},
"scripts": {
"test:dependencies": "updates --update ./",
}
}
Running npm run test:dependencies
(or whatever your dependency update script is called) will check your package.json
for the latest versions of every package listed, and it'll let you know when the latest version was published.运行npm run test:dependencies
(或任何你的依赖更新脚本)将检查你的package.json
中列出的每个包的最新版本,它会在最新版本发布时通知你。 Run npm i
after that and you'll be up to date!之后运行npm i
,您将是最新的!
Also, unlike npm-check-updates
, updates
has zero dependencies (ncu has 29, at the time of this post).此外,与npm-check-updates
不同, updates
的依赖项为零(在本文发布时,ncu 有 29 个)。
Alternative is替代方案是
"dependencies":{
"foo" : ">=1.4.5"
}
everytime you use npm update , it automatically update to the latest version.每次使用 npm update 时,它都会自动更新到最新版本。 For more version syntax, you may check here: https://www.npmjs.org/doc/misc/semver.html有关更多版本语法,您可以在这里查看: https ://www.npmjs.org/doc/misc/semver.html
Solution without additional packages无需额外软件包的解决方案
Change every dependency's version to *
:将每个依赖项的版本更改为*
:
"dependencies": {
"react": "*",
"react-google-maps": "*"
}
Then run npm update --save
.然后运行npm update --save
。
Some of your packages were updated, but some not?您的一些软件包已更新,但有些没有?
"dependencies": {
"react": "^15.0.1",
"react-google-maps": "*"
}
This is the tricky part, it means your local version of "react" was lower than the newest one.这是棘手的部分,这意味着您本地版本的“react”低于最新版本。 In this case npm downloaded and updated "react" package.在这种情况下,npm 下载并更新了“react”包。 However your local version of "react-google-maps" is the same as the newest one.但是,您本地版本的“react-google-maps”与最新版本相同。
If you still want to "update" unchanged *
, you have to delete these modules from node_modules
folder.如果您仍想“更新”未更改的*
,则必须从node_modules
文件夹中删除这些模块。
eg delete node_modules/react-google-maps
.例如删除node_modules/react-google-maps
。
Finally run again npm update --save
.最后再次npm update --save
。
"dependencies": {
"react": "^15.0.1",
"react-google-maps": "^4.10.1"
}
Do not forget to run npm update --save-dev
if you want to update development dependencies.如果要更新开发依赖项,请不要忘记运行npm update --save-dev
。
Greenkeeper if you're using Github.如果您使用的是 Github,则为 Greenkeeper。 https://greenkeeper.io/ https://greenkeeper.io/
It's a Github integration and incredibly easy to set things up.这是一个 Github 集成,设置起来非常容易。 When installed, it automatically creates pull requests in repositories you specify (or all if wanted) and keeps your code always up-to-date, without forcing you to do anything manually.安装后,它会自动在您指定的存储库(或所有如果需要)中创建拉取请求,并使您的代码始终保持最新,而无需您手动执行任何操作。 PRs should then trigger a build on a CI service and depending on a successful or failed check you can keep figuring out what's triggering the issue or when CI passes simply merge the PR.然后 PR 应该在 CI 服务上触发构建,根据检查成功或失败,您可以继续找出触发问题的原因或 CI 何时通过,只需合并 PR。
At the bottom, you can see that the first build failed at first and after a commit ("upgrade to node v6.9") the tests pass so I could finally merge the PR.在底部,您可以看到第一次构建首先失败,并且在提交(“升级到节点 v6.9”)之后测试通过,所以我最终可以合并 PR。 Comes with a lot of emoji, too.还带有很多表情符号。
Another alternative would be https://dependencyci.com/ , however I didn't test it intensively.另一种选择是https://dependencyci.com/ ,但是我没有对其进行深入测试。 After a first look Greenkeeper looks better in general IMO and has better integration.乍看之下,Greenkeeper 在 IMO 总体上看起来更好,并且具有更好的集成性。
An automatic update is possible with NPM-script:使用 NPM 脚本可以自动更新:
{
"_cmd-update-modules": "npm run devops-update-modules",
"scripts": {
"create-global-node-modules-folder": "if not exist \"%appdata%\\npm\\node_modules\" mkdir %appdata%\\npm\\node_modules",
"npm-i-g": "npm i npm@latest -g",
"npm-check-i-g": "npm i npm-check@latest -g",
"eslint-i-g": "npm i eslint@latest -g",
"npm-check-u-l": "npm-check \"C:\\Program Files\\nodejs\\node_modules\\npm\" -y",
"npm-check-u-g": "npm-check \"C:\\Program Files\\nodejs\\node_modules\\npm\" -y -g",
"npm-deep-update-l": "npm update --depth 9999 --dev",
"npm-deep-update-g": "npm update --depth 9999 --dev -g",
"npm-cache-clear": "npm cache clear --force",
"devops-update-modules": "npm run create-global-node-modules-folder && npm run npm-i-g && npm run npm-check-i-g && npm run eslint-i-g && npm run npm-check-u-l && npm run npm-check-u-g && npm run npm-deep-update-l && npm run npm-deep-update-g && npm run npm-cache-clear"
}
}
For further details and step-by-step manual: https://stackoverflow.com/a/34295664有关更多详细信息和分步手册: https ://stackoverflow.com/a/34295664
Should get you the latest wanted versions compatible for your app.应该为您提供与您的应用程序兼容的最新想要的版本。 But not the latest versions.但不是最新版本。
The very easiest way to do this as of today is use pnpm rather than npm and simply type:到目前为止,最简单的方法是使用 pnpm 而不是 npm,只需键入:
pnpm update --latest
https://github.com/pnpm/pnpm/releases/tag/v3.2.0 https://github.com/pnpm/pnpm/releases/tag/v3.2.0
This can be helpfully npm outdated | awk '{ if (NR>1) {print $1"@"$4} }' | xargs npm i
这可能很有帮助npm outdated | awk '{ if (NR>1) {print $1"@"$4} }' | xargs npm i
npm outdated | awk '{ if (NR>1) {print $1"@"$4} }' | xargs npm i
Expanding on @kozlovd answer I built a bash script to update any npm script in 2 steps:扩展@kozlovd 答案,我构建了一个 bash 脚本,分两步更新任何 npm 脚本:
This gives you the number of npm packages, if you get an error count them manually.这将为您提供 npm 包的数量,如果您遇到错误,请手动计算它们。
npm list | wc -l
Here replace NUM_PKGS with the number of packages and if you got "UNMET DEPENDENCY" error in the previous command replace $2 for $4.这里将 NUM_PKGS 替换为包的数量,如果在前面的命令中出现“UNMET DEPENDENCY”错误,请将 $2 替换为 $4。
NUM_PKGS=9999; npm list --no-unicode | awk -v NUM_PKGS=$NUM_PKGS '{\
if (NR>1 && NR <NUM_PKGS) {\
pver=A[split($2,A,"@")];\
print substr($2,0,length($2)-length(pver))"latest";\
}\
}' | xargs -r npm i
Explanation:解释:
The command Nº 2 first gets the package names and only operates over the lines with them in case of an "UNMET DEPENDENCY" error, then awk iterates over each package name, it gets the version value and replaces it by "latest", lastly all those packages with the version replaced are collected by xargs who concatenates them after "npm i" to finally install all of them with the latest version. The command Nº 2 first gets the package names and only operates over the lines with them in case of an "UNMET DEPENDENCY" error, then awk iterates over each package name, it gets the version value and replaces it by "latest", lastly all被替换版本的那些包由 xargs 收集,xargs 在“npm i”之后将它们连接起来,最终将它们全部安装到最新版本。
This steps can update a new project with packages without a set version or an existing project此步骤可以使用没有设置版本或现有项目的包更新新项目
Instead of installing yet another node module for a one-off use-case, you can just do this in your shell...您可以在 shell 中执行此操作,而不是为一次性用例安装另一个节点模块...
npm install $(npm outdated | tail -n +2 | awk '{print $1}' | sed -e 's/$/@latest/g' | tr '\n' ' ')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.