raphaelsaunier / npm-install-in-workspace-issue

Reproduction of an issue with npm 7.7.4 workspaces

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This repository aims to exhibit and narrow down an issue with npm workspaces, where running npm install to install a new dependency in a workspace that already depends on another local package.

Steps to reproduce

  • Navigate to a workspace: cd scoped/workspace-b or cd unscoped/workspace-b
  • Try to install a dependency: npm install left-pad

Current Behaviour

Using scoped packages

$ …/scoped/workspace-b > npm install left-pad
npm ERR! code E404
npm ERR! 404 Not Found - GET https://registry.npmjs.org/@foo%2fworkspace-a - Not found
npm ERR! 404
npm ERR! 404  '@foo/workspace-a@0.0.1' is not in the npm registry.
npm ERR! 404 You should bug the author to publish it (or use the name yourself!)
npm ERR! 404
npm ERR! 404 Note that you can also install from a
npm ERR! 404 tarball, folder, http url, or git url.

Using unscoped packages

Slightly different error, but identical result with unscoped packages:

$ …/unscoped/workspace-b > npm install left-pad
npm ERR! code ETARGET
npm ERR! notarget No matching version found for workspace-a@0.0.1.
npm ERR! notarget In most cases you or one of your dependencies are requesting
npm ERR! notarget a package version that doesn't exist.

Expected Behaviour

The new dependency I am trying to install should be installed with no errors and local depenencies present in the same mono-repo and registered as workspaces should be identified and linked correctly.

How does Yarn handle this?

For comparison, Yarn is able to handle this situation just fine; running yarn add left-pad inside workspace-b succeeds and the local dependency on workspace-a is correctly resolved. The resulting project state can be seen on the yarn branch of this repository.

$ …/unscoped/workspace-b > yarn add left-pad
yarn add v1.22.10
warning package.json: No license field
info No lockfile found.
warning package-lock.json found. Your project contains lock files generated by tools other than Yarn. It is advised not to mix package managers in order to avoid resolution inconsistencies caused by unsynchronized lock files. To clear this warning, remove package-lock.json.
[1/4] 🔍  Resolving packages...
warning left-pad@1.3.0: use String.prototype.padStart()
[2/4] 🚚  Fetching packages...
[3/4] 🔗  Linking dependencies...
[4/4] 🔨  Building fresh packages...
success Saved lockfile.
success Saved 1 new dependency.
info Direct dependencies
info All dependencies
└─ left-pad@1.3.0
✨  Done in 0.35s.

About

Reproduction of an issue with npm 7.7.4 workspaces


Languages

Language:JavaScript 100.0%