如何在PNPM版本之间切换?
我目前正在使用使用PNPM 6但已安装PNPM 7的应用程序。我找不到任何文档,向我展示了如何在版本之间安装和切换。谢谢你!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我目前正在使用使用PNPM 6但已安装PNPM 7的应用程序。我找不到任何文档,向我展示了如何在版本之间安装和切换。谢谢你!
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(10)
如果您已经通过node.js corepack :
对于节点V18,则可以运行:
这是 for node v18
for node v20+您可以运行:
这是 corepack docs for Node V20
If you have installed pnpm through Node.js corepack:
For Node v18 you can run:
Here are the corepack docs for Node v18
For Node v20+ you can run:
Here are the corepack docs for Node v20
如果您希望使用想要的PNPM版本,请使用
npx
:例如,我在全球安装了PNPM 8,但想为取决于PNPM 6的项目做出贡献。这是我怎么做:
If you wish for a one-liner to use whichever pnpm version you want, use
npx
:For example, I have pnpm 8 installed globally but want to contribute to a project that depends on pnpm 6. This is how I do it:
我也可以使用 node.js/corepack 。对于不同的项目,我必须在6和7之间跳跃。
凭借最新版本的Node.js(16.17+),在PNPM的最新版本的最新版本之间更容易切换。对于最新版本7,您要键入:
对于第6版的最新版本:
它也在 pnpm。
I'm also going with node.js/corepack. I have to jump between versions 6 and 7 for different projects.
With a recent version of node.js (16.17+) it's even easier to switch between the most recent of major versions of pnpm. For the latest of version 7 you'd type:
For the latest of version 6:
It's also described in the installation doc of pnpm.
可能有一个更好的方法,但我只是卸载了版本7并安装了6版。我使用纱线做到了这一点,但是您可以使用卸载/安装文档中列出的任何方法来完成此操作。只需确保使用最初用于安装它的方法卸载(NPM,纱,酿造等)即可。
这是我所做的:
当前,似乎没有类似于NVM的解决方案。 参考
There may be a better way but I just uninstalled version 7 and installed version 6. I did this with yarn but you can do it with any method listed in the uninstall/install documentation. Just make sure you uninstall using the method you originally used to install it (npm, yarn, brew, etc.).
This is what I did:
Currently, it seems there is no solution similar to nvm. Reference
就我而言,在Ubuntu 22.04上,我做了以下内容。
In my case, to setup the nextauthjs local environment on Ubuntu 22.04 I did the followings.
nvm use v18.12.0
corepack enable && corepack prepare [email protected] --activate
(corepack enable pnpm
is should be enough too).您可以做到这一点,
您可以设置Bash别名
you can do it
you can set bash alias
我在2022年或2023年在Windows上安装了PNPM。
我进行了全局安装,但是“ PNPM -V”总是返回旧版本:
“ PNPM -V”最终在运行以下命令之后给了我8.5.1:
I installed pnpm with Vite in 2022 or 2023 on Windows.
I did the global installations but 'pnpm -v' always returned the old version:
The 'pnpm -v' finally gave me 8.5.1 after running the following commands:
如果您正在使用Windows
If you are using windows
如果您运行
corepack enable
,则可以在project package.json中指定PNPM版本。
例如,
在运行
PNPM安装
或任何pnpm
命令时,CorePack将下载并使用指定的PNPM版本,而无需任何其他安装。当并非所有项目都使用相同的锁定格式时,这特别有用。
if you run
corepack enable
you can then specify the pnpm version in the project package.json.
e.g.
when running
pnpm install
or anypnpm
command, corepack will download and use the specified pnpm version without any further installation.This is especially helpfull when not all projects are using the same lockfile format.
更多详细信息:
https://pnpm.io/installation#using-corepack
more details:
https://pnpm.io/installation#using-corepack