Skip to content

v11 fetch followed by install recreates node_modules #11488

@szegheo

Description

@szegheo

Last pnpm version that worked

10.33.3

pnpm version

11.0.6

Code to reproduce the issue

I have a Dockerfile where I use pnpm fetch for the same reason described in its documentation page. After upgrading to pnpm v11, I noticed that the pnpm install command (followed by fetch) always forces a recreation of node_modules.

demo.zip (minimal demo project for v10 and v11)

package.json

{
  "name": "demo",
  "private": true,
  "version": "0.0.0",
  "type": "module",
  "main": "app.js",
  "license": "UNLICENSED",
  "packageManager": "pnpm@11.0.6",
  "scripts": {
    "start": "node app.js"
  },
  "dependencies": {
    "chalk": "^5.6.2"
  }
}

app.js

import {Chalk} from 'chalk';
const myChalk = new Chalk({level: 1});
console.log(myChalk.bgGreen("Hello world!"));

demo.sh (run this to reproduce)

export CI=true
echo Current pnpm version: $(pnpm -v)
echo "\n--- FETCH ---\n"
pnpm fetch --prod
echo "\n--- INSTALL ---\n"
pnpm install --offline --prod --frozen-lockfile
echo "\n--- START ---\n"
pnpm start

pnpm-lock.yaml

lockfileVersion: '9.0'

settings:
  autoInstallPeers: true
  excludeLinksFromLockfile: false

importers:

  .:
    dependencies:
      chalk:
        specifier: ^5.6.2
        version: 5.6.2

packages:

  chalk@5.6.2:
    resolution: {integrity: sha512-7NzBL0rN6fMUW+f7A6Io4h40qQlG+xGmtMxfbnH/K7TAtt8JQWVQK+6g0UXKMeVJoyV5EkkNsErQ8pVD3bLHbA==}
    engines: {node: ^12.17.0 || ^14.13 || >=16.0.0}

snapshots:

  chalk@5.6.2: {}

Expected behavior

The node_modules not to be recreated.
Running the script second time does not breaks node_modues (ERR_MODULE_NOT_FOUND)

See the screenshot from v10.33.3:

Image

Actual behavior

After fetch, the install recreates node_modules.
Running the script again breaks node_modules, the demo app throws ERR_MODULE_NOT_FOUND error.

Image

Additional information

It is also interesting that the fetch command generates a node_modules folder at all. I thought that fetch only loads packages into the virtual store. (However, this was already reported in 2024: #8623 (still open))

The same is true when I manually run this in command line (no CI):
PNPM_HOME=/demo/store pnpm fetch --prod

Node.js version

22.21.1

Operating System

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions