简体   繁体   English

npm install package.json 中指定的确切包版本

[英]npm install the exact package version specified in package.json

Currently, If I run npm install , it installs the updated version of already installed packages.目前,如果我运行npm install ,它会安装已安装软件包的更新版本。 How can I install the exact version as specified in the package.json file?如何安装package.json文件中指定的确切版本?

By default npm installs packages using ^ which means any version in the same major range, you can switch this behaviour by using --save-exact默认情况下,npm 使用 ^ 安装软件包,这意味着同一主要范围内的任何版本,您可以使用 --save-exact 切换此行为

// npm
npm install --save --save-exact react

// yarn
yarn add --exact react

I created a blog post about this if anyone is looking for this in the future.如果有人在未来寻找这个,我创建了一篇关于这个的博客文章。

https://www.dalejefferson.com/articles/2018-02-04-how-to-save-exact-npm-package-versions/ https://www.dalejefferson.com/articles/2018-02-04-how-to-save-exact-npm-package-versions/

That behavior is really driven by the one specifying the versions in the package.json.这种行为实际上是由在 package.json 中指定版本的行为驱动的。 If the version number looks like "1.0.0", without any other symbols, the exact version (1.0.0) should be installed.如果版本号看起来像“1.0.0”,没有任何其他符号,则应安装确切的版本 (1.0.0)。

So what you could do is simply modify the package.json and run a npm install then.所以你可以做的是简单地修改 package.json 然后运行npm install Be sure to clear out the node_modules directory before you do that.在执行此操作之前,请务必清除 node_modules 目录。

https://docs.npmjs.com/files/package.json#dependencies https://docs.npmjs.com/files/package.json#dependencies

You can also open package.json and change value for the package you want to remain exact.您还可以打开package.json并更改要保持准确的包的值。 From "vue": "^2.6.10" to "vue": "2.6.10" ."vue": "^2.6.10""vue": "2.6.10" Notice the lack of ^ sign in front of the version number.请注意版本号前面缺少^符号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM