确定兼容性
官网上兼容性表格
以下是各版本 pnpm 与各版本 Node.js 之间的兼容性表格
所以安装pnpm,首先要确定安装的node版本是多少,如下所示node版本是14
>node -v
v14.5.0
C:\WINDOWS\system32>npm -v
6.14.5
C:\WINDOWS\system32>pnpm -v
'pnpm' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
那么注意了,此时如果直接安装pnpm会报错,提示版本不兼容
C:\WINDOWS\system32>npm install pnpm -g
D:\software\node\install\node_global\pnpx -> D:\software\node\install\node_global\node_modules\pnpm\bin\pnpx.cjs
D:\software\node\install\node_global\pnpm -> D:\software\node\install\node_global\node_modules\pnpm\bin\pnpm.cjs
npm WARN notsup Unsupported engine for pnpm@9.12.1: wanted: {"node":">=18.12"} (current: {"node":"14.5.0","npm":"6.14.5"})
npm WARN notsup Not compatible with your version of node/npm: pnpm@9.12.1
+ pnpm@9.12.1
added 1 package in 4.101s
C:\WINDOWS\system32>pnpm -v
ERROR: This version of pnpm requires at least Node.js v18.12
The current version of Node.js is v14.5.0
Visit https://r.pnpm.io/comp to see the list of past pnpm versions with respective Node.js version support.
卸载pnpm
//npm uninstall pnpm 此命令不生效
C:\WINDOWS\system32>npm rm -g pnpm
removed 1 package in 0.632s
node14安装pnpm,版本限制在7以下,安装成功
C:\WINDOWS\system32>npm install -g pnpm@6.0.0
npm WARN deprecated pnpm@6.0.0: This version had issues with Webpack, Vite and some other toolings. These issues were fixed in v6.0.1
D:\software\node\install\node_global\pnpm -> D:\software\node\install\node_global\node_modules\pnpm\bin\pnpm.cjs
D:\software\node\install\node_global\pnpx -> D:\software\node\install\node_global\node_modules\pnpm\bin\pnpx.cjs
+ pnpm@6.0.0
added 1 package in 3.262s
C:\WINDOWS\system32>pnpm -v
6.0.0