npm / npm/cli

When using a workspace, the transitive peerDependency of a package dependency is installed in the workspace's node_modules instead of being hoisted with the package

Open
#9,337 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

STR:

git clone https://github.com/julienw/vitest-types-issue
npm ci
cd packages/frontend
npx tsc

=> Typescript outputs errors because it can't find the right dependencies.

The repository has a single workspace in packages/frontend. There's no dependency defined at the workspace root.

This workspace contains these dependencies:

  "devDependencies": {
    "@vitest/browser-playwright": "4.1.5",
    "typescript": "6.0.3",
    "vitest": "4.1.5"
  }

@vitest/browser-playwright is also an optional peerDependency of vitest, with the same version.

When installing with npm ci (or npm i), we get this layout (I removed the unrelated packages from the output):

in /node_modules:

playwright/
playwright-core/
typescript/
vite/
'@vitest'/
- browser/
- expect/
- mocker/
- pretty-format/
- runner/
- snapshot/
- spy/
- utils/
vitest/

in /packages/frontend/node_modules:

@vitest/browser-playwright/

There's an error because vitest/browser (/!\ it's not @vitest/browser) exports types from @vitest/browser-playwright, but because @vitest/browser-playwright is in the workspace, typescript doesn't find it.

I think it's a bug in npm because:

  • @vitest/browser-playwright is a peerDependency of vitest so it should be installed along it
  • even dependencies of @vitest/browser-playwright are hoisted to the root (eg: the dependency @vitest/browser or the non-optional peer dependency playwright).

What do you folks think?

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Use the linked reproduction repository: run npm ci, change to packages/frontend, and run npx tsc to confirm the missing type resolution. Inspect npm's workspace dependency installation and hoisting behavior around the reported node_modules layouts; done means the transitive peer dependency is installed with the package at the root and npx tsc completes without these errors.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, typescript
Domain
cli, developer-experience, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Clearly specified
Newbie friendliness
66/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.