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
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-playwrightis a peerDependency ofvitestso it should be installed along it- even dependencies of
@vitest/browser-playwrightare hoisted to the root (eg: the dependency@vitest/browseror the non-optional peer dependencyplaywright).
What do you folks think?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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