node.js npm 更新到特定版本(和收缩包装)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42816151/
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
npm update to specific version (and shrinkwrap)
提问by Yves L L
I'm using NPM and shrinkwrap (latest up to date version) to maintain my packages.
我正在使用 NPM 和 shrinkwrap(最新版本)来维护我的包。
At the moment, one of my package current version is 1.1.0. The latest version of this package is 2.2.0.
目前,我的包当前版本之一是 1.1.0。这个包的最新版本是 2.2.0。
I want to update/upgrade this specific package to version 2.0.0(and not the latest 2.2.0).
我想将此特定软件包更新/升级到2.0.0版(而不是最新的 2.2.0 版)。
I thought that the procedure would be:
我以为程序是:
npm installin order to make sure that I'm synchronized with the npm-shrinkwrapnpm update [email protected]npm shrinkwrapgit add . && git commit -m "Updating package myPackage to version 2.0.0"
npm install为了确保我与 npm-shrinkwrap 同步npm update [email protected]npm shrinkwrapgit add . && git commit -m "Updating package myPackage to version 2.0.0"
This doesn't seem to be the right road to go. It doesn't update the package.jsonand it always jump to the latest version. I have no control over this command to select the specific version I want.
这似乎不是正确的道路。它不会更新package.json并且总是跳转到最新版本。我无法控制此命令来选择我想要的特定版本。
I read the documentation about npm updateand couldn't find the proper way to update the package to a specific version.
我阅读了有关文档npm update,但找不到将包更新到特定版本的正确方法。
How to do this ? Would npm install --save [email protected]would be the correct procedure ? Then what will be the purpose of having npm updatecommand ?
这该怎么做 ?会npm install --save [email protected]是正确的程序吗?那么拥有npm update命令的目的是什么?
Solution:npm install [email protected] --save
解决方案:npm install [email protected] --save
回答by Gregory Bell
npm updatedoesn't seem to interact with the shrinkwrap file as far as I can tell. But you can use npm installto set the version of a package.
npm update据我所知,似乎没有与收缩包装文件进行交互。但是你可以npm install用来设置包的版本。
This will update both package.jsonand npm-shrinkwrap.json:
这将更新package.json和npm-shrinkwrap.json:
npm install [email protected] --save
npm install [email protected] --save
回答by Alan
You can enter to package.jsonand write the version yourself on the dependencies. After that do npm installand it will install the correct version.
您可以package.json在依赖项上输入并自己编写版本。之后,npm install它会安装正确的版本。

