我应该更新我的 npm 版本还是使用 node.js 提供的一个版本? [英] Should I update my npm version or use the one node.js provides?
问题描述
我有一个使用 node.js 14.16.0 的项目.我和我的团队成员都使用那个版本.我使用 npm 6.14.11,我的团队成员使用 npm 7.x.x.这导致 package-lock.json 不同;lockFileVersion
属性在我的 PC 上为 1,但在他们的 PC 上为 2.
I have a project that uses node.js 14.16.0. Both me and my teammember use that version.
I use npm 6.14.11 and my teammember uses npm 7.x.x.
This results in the package-lock.json being different; the lockFileVersion
property is 1 on my PC but 2 on theirs.
我已经在使用 nvm
并且正在考虑添加一个 .nvmrc
以便每个人始终使用相同的节点版本,但这并不能解决 npm 版本问题.
I already use nvm
and am considering to add a .nvmrc
so everyone always uses the same node version, but this doesn't fix the npm version issue.
我认为使用已安装的 node.js 版本提供的 npm 版本是个好主意.如果下一个大型 LTS 版本使用新的 npm 版本,项目将切换到该版本.但是在 NPM 的网站上,他们说:
I believe that it is a good idea to use the npm version that the installed node.js version provides. If the next big LTS release uses a new npm version, the project will switch to that. But on NPM's site they say:
npm 是一个独立于 Node.js 的项目,更新频率更高.因此,即使您刚刚下载了 Node.js(以及 npm),您也可能需要更新您的 npm.幸运的是,npm 知道如何自我更新!
npm is a separate project from Node.js, and tends to update more frequently. As a result, even if you’ve just downloaded Node.js (and therefore npm), you’ll probably need to update your npm. Luckily, npm knows how to update itself!
这让我相信我应该一直更新.
Which makes me believe I should always update.
但他们也说:
Node.js 有很多版本!要有效地使用 Node.js 以及 npm,您需要确保您使用的是 Node.js 团队支持的版本.通常,您应该使用标记为LTS"的 Node.js 版本.
Node.js has lots of versions! To use Node.js, and therefore npm, effectively, you’ll want to make sure that you are on a version that is supported by the Node.js team. In general, you should use the version of Node.js labelled "LTS".
这让我相信我不应该更新而只使用 node.js 提供的一个.
Which makes me believe I shouldn't update and just use the one node.js provides.
最佳实践是什么?NPM 没有 LTS 的概念吗?
What is the best practice? Does NPM not have a concept of LTS?
推荐答案
npm 有 LTS 的概念.事实上,他们标记了一个发布 lts
,因此您可以npm install -g npm@lts
并获得最新的 lts 版本,在撰写本文时为 7.6.3.
npm has a concept of LTS. In fact, they tag a release lts
so you can npm install -g npm@lts
and get the latest lts version, which as of this writing is 7.6.3.
npm 将继续支持任何主要版本的 npm,只要它附带的节点版本仍然受支持.因此他们将支持 npm@6,直到 14 停产,因为 npm@6 随版本 14 一起提供.
npm will continue to support any major version of npm as long as it shipped with a version of node that is still supported. So they will support npm@6 until 14 goes EOL because npm@6 shipped with version 14.
也就是说,npm@7 是 npm 的当前版本,只要支持 14,它也会在 14 上得到支持.
That said, npm@7 is the current version of npm and it too will be supported on 14 as well for as long as 14 is supported.
如有疑问,请使用 npm@lts
(在撰写本文时为第 7 版).但是,如果您并不真正关心一种或另一种方式并且不想强迫您的同事更新,只要支持 Node.js 14,npm@6
将继续接收更新.不过,我建议使用 npm install -g npm@6
更新到最新的 npm@6
.任一版本(npm@6
或 npm@7
)都应该可以正常工作.您只需要与您的同事选择一个以避免 package-lock.json
流失(或不关心锁文件流失).
If in doubt, use npm@lts
(which is version 7 as of this writing). However, if you don't really care one way or the other and don't want to force your coworker to update, npm@6
will continue to receive updates as long as Node.js 14 is supported. I would recommend updating to the latest npm@6
with npm install -g npm@6
though. Either version (npm@6
or npm@7
) should work just fine. You just need to pick one with your coworker to avoid the package-lock.json
churn (or not care about the lockfile churn).
这篇关于我应该更新我的 npm 版本还是使用 node.js 提供的一个版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!