NPM 8 workspaces - Install one package as the dependency for another package in monorepo
Asked Answered
S

1

17

Say I have the following structure

packages
  - @my-scope/packageA
  - @my-scope/packageB
  - @my-scope/packageC

Let's say I want to install packageA as a dependency of packageB. With NPM 8 workspaces I would think this ought to do it: npm install @my-scope/packageA --workspace=@my-scope/packageB

Instead I get this:

npm ERR! 404 Not Found - GET https://registry.npmjs.org/@my-scope%2fpackageA - Not found 
npm ERR! 404
npm ERR! 404  '@my-scope/packageA@*' is not in this 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.

Clearly it is trying to get it from the registry (and no, I haven't published yet, not ready) but I want it to recognize that this dependency is in my project as a workspace. Anyone know why this might be happening? I haven't found many good resources explaining how to install dependencies from inside your monorepo (I don't even know what those are called...).

Sharleensharlene answered 15/12, 2021 at 23:32 Comment(0)
S
6

The problem you are facing has been reported as a bug: https://github.com/npm/cli/issues/3637

It has been marked as fixed.

Please try to install the latest version of npm (8.8.0 as of this writing) and see if your problem has been resolved.

Stepparent answered 3/5, 2022 at 17:18 Comment(4)
If you're still hitting this error after updating npm, try removing the entry for packageA from the package.json of packageB. Then explicitly choose the local version when installing. npm install @my-scope/packageA --workspace=@my-scope/packageB@<LOCAL_VERSION>Kolosick
it may be marked as fixed, but it sure isn't, not even in node 20Phalangeal
@Phil, I'm not on the npm maintenance team, so cannot say for sure, but I would guess that opening a new issue on GitHub with all the symptoms you observe would be the best course of action. I'm not using node 20 yet, so I cannot contribute much to the discussion, unfortunately.Stepparent
@Stepparent sorry, my bad. It actually is working, I just had wrong package name in the package.json (my package folder was "something" but the actual package-name was "@my-org/something").Phalangeal

© 2022 - 2024 — McMap. All rights reserved.