如何更新node.js包,以便更改package.json

时间:2017-10-25 09:06:19

标签: node.js npm

看起来npm up [package]无法正常工作。这是一个包没有更新的例子。

在package.json

"dependencies": {
    "vasync": "^1.6.4"
}

检查版本:

$ npm outdated
vasync  1.6.4   1.6.4   2.1.0  app

尝试更新:

$ npm up vasync

现在再次检查,结果是一样的:

$ npm outdated
vasync  1.6.4   1.6.4   2.1.0  app

npm update实际上做了什么?如何使用它来更新包本身和package.json

2 个答案:

答案 0 :(得分:0)

npm up vasync --save

这应该可以完美地工作,如果你仍然得到相同的结果,请尝试详细模式,例如

❯ npm update rxjs --save --verbose
npm info it worked if it ends with ok
npm verb cli [ '/usr/local/Cellar/node/8.2.1/bin/node',
npm verb cli   '/usr/local/bin/npm',
npm verb cli   'update',
npm verb cli   'rxjs',
npm verb cli   '--save',
npm verb cli   '--verbose' ]
npm info using npm@5.5.1
npm info using node@v8.2.1
npm verb npm-session 113475d097da3551
npm verb request uri http://registry.npmjs.org/rxjs
npm verb request no auth needed
npm info attempt registry request try #1 at 3:22:03 PM
npm verb request id ac8c2e37f0875abd
npm http request GET http://registry.npmjs.org/rxjs
npm http 200 http://registry.npmjs.org/rxjs
npm verb headers { server: 'nginx/1.10.1',
npm verb headers   'content-type': 'application/json',
npm verb headers   'last-modified': 'Tue, 24 Oct 2017 17:52:42 GMT',
npm verb headers   etag: 'W/"59ef7dea-36f8e"',
npm verb headers   'content-encoding': 'gzip',
npm verb headers   'cache-control': 'max-age=300',
npm verb headers   'content-length': '14997',
npm verb headers   'accept-ranges': 'bytes',
npm verb headers   date: 'Wed, 25 Oct 2017 09:22:04 GMT',
npm verb headers   via: '1.1 varnish',
npm verb headers   age: '243',
npm verb headers   connection: 'keep-alive',
npm verb headers   'x-served-by': 'cache-bma7027-BMA',
npm verb headers   'x-cache': 'HIT',
npm verb headers   'x-cache-hits': '2',
npm verb headers   'x-timer': 'S1508923324.118963,VS0,VE0',
npm verb headers   vary: 'Accept-Encoding, Accept' }
npm verb outdated not updating rxjs because it's currently at the maximum version that matches its specified semver range
npm verb exit [ 0, true ]
npm info ok 

在我的情况下,它说没有更新rxjs,因为它目前处于与其指定的semver范围匹配的最大版本

答案 1 :(得分:-1)

如果要在package.json中添加依赖项,请尝试使用此命令:

npm update {package.name} --save

参数--save让节点知道您想要反映package.json中的更改,因此当您部署项目并安装软件包时,它将被视为。

问候。