pnpm icon indicating copy to clipboard operation
pnpm copied to clipboard

`pnpm fetch` fails if at least one injected workspace dependency exists in the monorepo

Open patricktree opened this issue 1 year ago • 1 comments

Verify latest release

  • [X] I verified that the issue exists in the latest pnpm release

pnpm version

8.12.1, 9.2.0

Which area(s) of pnpm are affected? (leave empty if unsure)

Dependencies resolver, Lockfile, Store

Link to the code that reproduces this issue or a replay of the bug

https://github.com/pkerschbaum/pnpm-issue-fetch-not-working-with-injected-workspace-deps

Reproduction steps

Run pnpm test in the reproduction repository.

Describe the Bug

Given

  1. a workspace project which has a dependency on another workspace project
  2. the dependency is injected
  3. and only pnpm-lock.yaml is present

...then running pnpm fetch throws an error:

pkerschbaum@DESKTOP-VLV02P1:~/workspace/pnpm-issue-fetch-not-working-with-injected-workspace-deps$ p test

> [email protected] test /home/pkerschbaum/workspace/pnpm-issue-fetch-not-working-with-injected-workspace-deps
> rm -rf ./temp-dir-for-issue && mkdir ./temp-dir-for-issue && cp ./pnpm-lock.yaml ./pnpm-workspace.yaml ./temp-dir-for-issue/ && cd ./temp-dir-for-issue/ && pnpm fetch

Importing packages to virtual store
Already up to date
 ENOENT  ENOENT: no such file or directory, scandir '/home/pkerschbaum/workspace/pnpm-issue-fetch-not-working-with-injected-workspace-deps/temp-dir-for-issue/packages/package-b'

Expected Behavior

pnpm fetch should be able to fetch dependencies with pnpm-lock.yaml only. This is useful for Docker builds, as described in https://pnpm.io/cli/fetch#usage-scenario.

Which Node.js version are you using?

18.18.2

Which operating systems have you used?

  • [ ] macOS
  • [ ] Windows
  • [X] Linux

If your OS is a Linux based, which one it is? (Include the version if relevant)

Ubuntu 22.04.4 LTS (WSL)

patricktree avatar Jun 07 '24 11:06 patricktree

Hi! I had trouble with the same issue - turns out that my pnpm-lock.yaml had been broken by enabling injectWorkspacePackages: true in my already existing project to use pnpm deploy.

One of my injected workspaces was referenced by file:... instead of link:... in the lock file, causing a multitude of headaches and problems. This was likely caused by my packages being already present in the lock file before the injection flag has been set and one of them not being updated correctly.

Only way to repair it though has been deleting the lock file and creating a fresh one via pnpm i - none of the repair options did work unfortunately.

daniel-kneip avatar Jun 10 '25 19:06 daniel-kneip