gpt4 book ai didi

node.js - 我应该更新我的 npm 版本还是使用 node.js 提供的一个版本?

转载 作者:行者123 更新时间:2023-12-04 01:05:23 24 4
gpt4 key购买 nike

我有一个使用 node.js 14.16.0 的项目。我和我的团队成员都使用那个版本。
我使用 npm 6.14.11,我的团队成员使用 npm 7.x.x。
这导致 package-lock.json 不同; lockFileVersion属性在我的 PC 上为 1,但在他们的 PC 上为 2。
我已经在用 nvm并且正在考虑添加 .nvmrc所以每个人总是使用相同的 Node 版本,但这并不能解决 npm 版本问题。
我相信使用已安装的 node.js 版本提供的 npm 版本是个好主意。如果下一个大型 LTS 版本使用新的 npm 版本,项目将切换到该版本。但是在 NPM's site他们说:

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!


这让我相信我应该经常更新。
但他们也说:

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 提供的一个。
最佳做法是什么? NPM 没有 LTS 的概念吗?

最佳答案

npm 有一个 LTS 的概念。事实上,他们标记了一个发布 lts所以你可以 npm install -g npm@lts并获取最新的 lts 版本,在撰写本文时为 7.6.3。
只要 npm 随附的 node 版本仍然受支持,npm 将继续支持 npm 的任何主要版本。因此他们将支持 npm@6,直到 14 停产,因为 npm@6 随版本 14 一起提供。
也就是说,npm@7 是 npm 的当前版本,只要支持 14,它也将在 14 上得到支持。
如有疑问,请使用 npm@lts (这是撰写本文时的第 7 版)。但是,如果您并不真正关心一种或另一种方式并且不想强制您的同事更新,npm@6只要支持 Node.js 14,就会继续接收更新。我建议更新到最新的 npm@6npm install -g npm@6尽管。任一版本( npm@6npm@7 )都应该可以正常工作。你只需要和你的同事选一个就可以避免 package-lock.json流失(或不关心锁文件流失)。

关于node.js - 我应该更新我的 npm 版本还是使用 node.js 提供的一个版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66673012/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com