npm / npm/cli

[BUG] workspace packages using different major versions of the same package causes issues

Open
#2,783 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Release 7.x
Dominant language
JavaScript
Stars
10.1k
Forks
4.7k
Avg merge
2d 2h
Merged PRs (30d)
19

Description

I had originally posted this in feedback:
https://github.com/npm/feedback/discussions/236#discussioncomment-407165

But was requested to post here as well:

Current Behavior:

TLDR;

I need to use multiple major versions of a single package. For this the only solution is a noHoist option, which I can't seem to find for NPM7 workspaces.

My case:

I have a NPM7 monorepo that holds a core lib focussed on data communication with a plugin system.
Some plugin in my workspace in ./packages use an NPM package (let's call it Y) of major version 2, while another uses Y of major version 3.

When the "docs" SPA in ./packages uses Y at v2 as well as the plugin that uses Y at v2, the docs cannot be launched because it's giving a conflict for version of package Y. It tries to use Y at v3.

How can I prevent "Y" from being hoisted in the NPM7 workspace? It's the only issue.

Expected Behavior:

I expect to be able to

Steps To Reproduce:

I can try to set up a repo that replicates this if requested.
I had already have to stop using workspaces because of this issue, so I don't have a reproduction ready to go. But am willing to create one if requested.

Environment:

npm: 7.5.6
macOS: 11.1

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

Begin with a minimal npm 7.5.6 workspace containing packages under ./packages, with one package requiring major version 2 of Y and another requiring major version 3. Confirm the hoisting conflict and document the expected workspace resolution behavior; the issue is done only when a reproducible case and an agreed resolution are established.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.