This question already has an answer here:
这个问题在这里已有答案:
- How do I update each dependency in package.json to the latest version? 30 answers
如何将package.json中的每个依赖项更新到最新版本? 30个答案
I want to update all my packages to the latest version:
我想将我的所有包更新到最新版本:
npm outdated
Result:
Package Current Wanted Latest Location
cordova 3.4.0-0.1.0 3.6.3-0.2.13 3.6.3-0.2.13 cordova
commander 2.0.0 2.0.0 2.3.0 npm-check-updates > commander
async 0.2.10 0.2.10 0.9.0 npm-check-updates > async
semver 2.2.1 2.2.1 4.0.3 npm-check-updates > semver
read-package-json 1.1.9 1.1.9 1.2.7 npm-check-updates > read-package-json
npm 1.3.26 1.3.26 2.1.2 npm-check-updates > npm
How can I do that?
我怎样才能做到这一点?
I tried it:
我尝试过这个:
sudo npm update -g cordova
And this too with no errors:
这也没有错误:
npm install npm-check-updates
But it's not working.
但它不起作用。
Thanks!!
3 个解决方案
#1
1
npm can! For example, we will update cordova to the latest version:
恩,可以!例如,我们将把cordova更新到最新版本:
sudo npm install -g cordova@latest
To update npm, just do the same:
要更新npm,请执行相同的操作:
sudo npm install -g npm@latest
#2
1
Depending on how they are listed in your package.json
you should edit the versions on each dependancy.
根据package.json中列出的方式,您应该编辑每个依赖项的版本。
an example would be:
一个例子是:
"devDependencies": {
"grunt": "*"
}
Setting the version to *
sets it to the latest version. Read about versioning dependancies here http://browsenpm.org/package.json
将版本设置为*将其设置为最新版本。请阅读http://browsenpm.org/package.json,了解版本控制依赖性
Once you have done that you can then tell NPM to install all the projects dependents.
完成后,您可以告诉NPM安装所有项目依赖项。
$ npm install
$ npm安装
Tip: if you are not automatically saving your projects dependants to your package.json, you should. Just add --save
to the end of your install query. Like so
提示:如果您没有自动将项目依赖项保存到package.json,那么您应该这样做。只需添加--save到安装查询的末尾即可。像这样
$ npm install grunt --save
$ npm install grunt --save
#3
-2
see this article HOW TO: Update all npm packages in your project at once
请参阅此文章如何:立即更新项目中的所有npm包
“scripts”: { “update:packages”: “node wipe-dependencies.js &&
rm -rf node_modules && npm update --save-dev
&& npm update --save” },
To run this on the command line:
要在命令行上运行它:
npm run update:packages
OR only update packages in the npm registry:
或者只更新npm注册表中的包:
const fs = require('fs')
const wipeDependencies = () => {
const file = fs.readFileSync('package.json')
const content = JSON.parse(file)
for (var devDep in content.devDependencies) {
if (!content.devDependencies[devDep].includes(git)) {
content.devDependencies[devDep] = '*'
}
}
for (var dep in content.dependencies) {
if (!content.dependencies[dep].includes(git)) {
content.dependencies[dep] = '*'
}
}
fs.writeFileSync('package.json', JSON.stringify(content))
}
if (require.main === module) {
wipeDependencies()
} else {
module.exports = wipeDependencies
}
#1
1
npm can! For example, we will update cordova to the latest version:
恩,可以!例如,我们将把cordova更新到最新版本:
sudo npm install -g cordova@latest
To update npm, just do the same:
要更新npm,请执行相同的操作:
sudo npm install -g npm@latest
#2
1
Depending on how they are listed in your package.json
you should edit the versions on each dependancy.
根据package.json中列出的方式,您应该编辑每个依赖项的版本。
an example would be:
一个例子是:
"devDependencies": {
"grunt": "*"
}
Setting the version to *
sets it to the latest version. Read about versioning dependancies here http://browsenpm.org/package.json
将版本设置为*将其设置为最新版本。请阅读http://browsenpm.org/package.json,了解版本控制依赖性
Once you have done that you can then tell NPM to install all the projects dependents.
完成后,您可以告诉NPM安装所有项目依赖项。
$ npm install
$ npm安装
Tip: if you are not automatically saving your projects dependants to your package.json, you should. Just add --save
to the end of your install query. Like so
提示:如果您没有自动将项目依赖项保存到package.json,那么您应该这样做。只需添加--save到安装查询的末尾即可。像这样
$ npm install grunt --save
$ npm install grunt --save
#3
-2
see this article HOW TO: Update all npm packages in your project at once
请参阅此文章如何:立即更新项目中的所有npm包
“scripts”: { “update:packages”: “node wipe-dependencies.js &&
rm -rf node_modules && npm update --save-dev
&& npm update --save” },
To run this on the command line:
要在命令行上运行它:
npm run update:packages
OR only update packages in the npm registry:
或者只更新npm注册表中的包:
const fs = require('fs')
const wipeDependencies = () => {
const file = fs.readFileSync('package.json')
const content = JSON.parse(file)
for (var devDep in content.devDependencies) {
if (!content.devDependencies[devDep].includes(git)) {
content.devDependencies[devDep] = '*'
}
}
for (var dep in content.dependencies) {
if (!content.dependencies[dep].includes(git)) {
content.dependencies[dep] = '*'
}
}
fs.writeFileSync('package.json', JSON.stringify(content))
}
if (require.main === module) {
wipeDependencies()
} else {
module.exports = wipeDependencies
}