Pnpm hangs during version switching in Replit workspaces

Companion issue to pnpm issue Replit version of pnpm hangs during version switching · Issue #14000 · pnpm/pnpm · GitHub

On Replit, pnpm -v hangs during version switching when a pnpm-workspace.yaml is present, eventually recursively spawning pnpm add pnpm@... commands until system resources are exhausted

As shown below, this reproduces with both:

A) Replit’s pnpm@10.26.1
B) latest pnpm@11.22.0

Reproduction

  1. Create a new empty project on Replit: visit Sign Up - Replit and click the Create empty project button

  2. Click the Open Library icon at the top right (the square divided by a horizontal line), then click the Files button at the top to show the files in the project

  3. Click the + at the top, to the right of Tools and Preview, and select Shell to open a terminal tab

  4. Run pnpm -v and install Replit’s Node tools when prompted:

    ~/workspace$ pnpm -v
    Install Replit's Node tools [y/n] y
    10.26.1
    
  5. Init a package.json, create an empty pnpm-workspace.yaml (required for repro), then switch to a different pnpm version:

    ~/workspace$ pnpm init
    Wrote to /home/runner/workspace/package.json
    
    {
      "name": "workspace",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "packageManager": "pnpm@10.26.1"
    }
    
    ~/workspace$ pnpm -v
    10.26.1
    
    ~/workspace$ touch pnpm-workspace.yaml
    
    ~/workspace$ pnpm pkg set packageManager="pnpm@10.26.2"
    
    ~/workspace$ cat package.json
    {
      "name": "workspace",
      "version": "1.0.0",
      "description": "",
      "main": "index.js",
      "scripts": {
        "test": "echo \"Error: no test specified\" && exit 1"
      },
      "keywords": [],
      "author": "",
      "license": "ISC",
      "packageManager": "pnpm@10.26.2"
    }
    
  6. Run pnpm -v - observe that it hangs :collision:

    ~/workspace$ pnpm -v
    

    If you wait long enough, pnpm eventually exhausts the available resources after recursively spawning the same version-switch command, followed by many repeated errors:

    node[1869]: pthread_create: Resource temporarily unavailable
    Warning: Failed to load CA certificates off thread: resource temporarily unavailable
     ERROR  Command was killed with SIGABRT (Aborted): pnpm add pnpm@10.26.2 --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=bin
    For help, run: pnpm help add
     ERROR  Command failed with exit code 1: pnpm add pnpm@10.26.2 --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=bin
    For help, run: pnpm help add
     ERROR  Command failed with exit code 1: pnpm add pnpm@10.26.2 --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=bin
    For help, run: pnpm help add
    ...
     ERROR  Command failed with exit code 1: pnpm add pnpm@10.26.2 --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=bin
    For help, run: pnpm help add
     ERROR  Command failed with exit code 1: pnpm add pnpm@10.26.2 --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=bin
    For help, run: pnpm help add
     ERROR  Command failed with exit code 1: pnpm add pnpm@10.26.2 --loglevel=error --allow-build=@pnpm/exe --no-dangerously-allow-all-builds --config.node-linker=hoisted --config.bin=bin
    For help, run: pnpm help add
    

This is also reproducible with the latest version pnpm@11.22.0 - upgrade with this:

  1. Delete the pnpm-workspace.yaml file if present (workaround required to switch versions)

  2. Open the .replit file in the Files pane on the right

  3. Change nodejs-20 to nodejs-22

  4. Click the + at the top, to the right of Tools and Preview, and select Shell to open a terminal tab

  5. Set and switch to pnpm 11.22.0:

    ~/workspace$ pnpm pkg set packageManager="pnpm@11.22.0"
    ~/workspace$ pnpm -v
    11.22.0
    
  6. Create an empty pnpm-workspace.yaml, switch the version and run pnpm -v - observe that it hangs :collision:

    ~/workspace$ touch pnpm-workspace.yaml
    ~/workspace$ pnpm pkg set packageManager="pnpm@11.21.0"
    ~/workspace$ pnpm -v
    

Investigation

I investigated a bit, and it seems like this problem may be related to Replit’s directory structure ($XDG_DATA_HOME and the pnpm store are inside the project directory - which is called /home/runner/workspace on Replit) :thinking:

~/workspace$ printf '%s\n' \
  "PWD=$PWD" \
  "HOME=$HOME" \
  "REPL_HOME=${REPL_HOME-}" \
  "XDG_DATA_HOME=${XDG_DATA_HOME-}" \
  "XDG_CONFIG_HOME=${XDG_CONFIG_HOME-}" \
  "PNPM_HOME=${PNPM_HOME-}"
PWD=/home/runner/workspace
HOME=/home/runner
REPL_HOME=/home/runner/workspace
XDG_DATA_HOME=/home/runner/workspace/.local/share
XDG_CONFIG_HOME=/home/runner/workspace/.config
PNPM_HOME=

~/workspace$ pnpm store path
/home/runner/workspace/.local/share/pnpm/store/v10

The Replit-provided pnpm is installed via Nix, while pnpm’s downloaded version used for version switching is inside the repository directory:

~/workspace$ which pnpm
/nix/store/61lr9izijvg30pcribjdxgjxvh3bysp4-pnpm-10.26.1/bin/pnpm

~/workspace$ find "$XDG_DATA_HOME/pnpm/.tools/pnpm" -maxdepth 2 -type d -print
/home/runner/workspace/.local/share/pnpm/.tools/pnpm
/home/runner/workspace/.local/share/pnpm/.tools/pnpm/11.22.0_tmp_3402
/home/runner/workspace/.local/share/pnpm/.tools/pnpm/11.22.0_tmp_3402/node_modules
/home/runner/workspace/.local/share/pnpm/.tools/pnpm/11.22.0_tmp_3402/bin

This means pnpm’s downloaded version is running from inside the same repository directory containing the pnpm-workspace.yaml

Upstream

The pnpm 10.26.1 behavior also looks similar to pnpm issue #11337 and PR #11346, both linked from the companion issue above

Environment

Replit default:

Node.js 20.20.0
pnpm 10.26.1
Ubuntu 24.04.4 LTS

Latest pnpm repro:

Node.js 22.22.0
pnpm 11.22.0
Ubuntu 24.04.4 LTS

Expected behavior

pnpm should switch versions without hanging

Workaround 1: Temporarily move pnpm-workspace.yaml during download

To avoid pnpm commands hanging while downloading new versions, temporarily move pnpm-workspace.yaml to a new name eg. pnpm-workspace2.yaml, run your command, and then move it back:

~/workspace$ mv pnpm-workspace.yaml pnpm-workspace2.yaml
~/workspace$ pnpm -v      # Downloads + installs new version (takes a few seconds) and then prints version
11.22.0
~/workspace$ mv pnpm-workspace2.yaml pnpm-workspace.yaml
~/workspace$ pnpm -v      # Still works, using the existing version downloaded
11.22.0

Workaround 2: Use npm_config_manage_package_manager_versions=false

To avoid pnpm commands hanging while downloading new versions, prefix your command with npm_config_manage_package_manager_versions=false - this will use the Replit version of pnpm, currently pnpm@10.26.1:

~/workspace$ npm_config_manage_package_manager_versions=false pnpm -v  # Does not download new version
10.26.1