Install pnpm as standalone

I used to install pnpm using the “standalone installation”, as described in the initial post, but I’m now using it with success via the corepack nix package. Quick example:

~$ mkdir testing-pnpm
~$ cd testing-pnpm/
~/testing-pnpm$ nix-shell -p nodejs_22 corepack_22

# ...

[nix-shell:~/testing-pnpm]$ which pnpm
/nix/store/kmm9fi163v374gv6i9qyi3crrhy85r1l-corepack-nodejs-22.3.0/bin/pnpm
[nix-shell:~/testing-pnpm]$
[nix-shell:~/testing-pnpm]$
[nix-shell:~/testing-pnpm]$ pnpm --version
! Corepack is about to download https://registry.npmjs.org/pnpm/-/pnpm-9.5.0.tgz
? Do you want to continue? [Y/n] Y

9.5.0

When we add some npm package for the first time, it will automatically add the packageManager field to package.json:

[nix-shell:~/testing-pnpm]$ pnpm init
[nix-shell:~/testing-pnpm]$ pnpm add underscore
! The local project doesn't define a 'packageManager' field. Corepack will now add one referencing pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903.
! For more details about this field, consult the documentation at https://nodejs.org/api/packages.html#packagemanager

Packages: +1
+
Progress: resolved 1, reused 0, downloaded 1, added 1, done

dependencies:
+ underscore 1.13.6

Done in 2.1s

[nix-shell:~/testing-pnpm]$ 

Here is how package.json looks like now:

{
  "name": "testing-pnpm",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "packageManager": "pnpm@9.5.0+sha512.140036830124618d624a2187b50d04289d5a087f326c9edfc0ccd733d76c4f52c3a313d4fc148794a2a9d81553016004e6742e8cf850670268a7387fc220c903",
  "dependencies": {
    "underscore": "^1.13.6"
  }
}
1 Like