Search code examples
monorepopnpm

`pnpm add` within a workspace does not add projects from workspace


I am working with a very simple monorepo with the following structure:

.npmrc
package.json
pnpm-workspaces.yml
packages/
  package-1/
  package-2/

When I cd into package-1, I am trying to add a reference to package-2 by doing the following:

pnpm add @myorg/package-2

But I get the error @myorg/package-2 is not in the npm registry, or you have no permission to fetch it.. I expect that pnpm add would detect that I'm inside a workspace and automatically link workspace packages. Am I missing something here?

Here is the relevant information you should need:

  • My packages use the @myorg/[package-name] convention inside of package.json "name" field.
  • The pnpm-workspaces.yml file is as follows:
    packages:
      - 'packages/**'
    
  • My .npmrc file is as follows:
    link-workspace-packages = true
    prefer-workspace-packages = true
    recursive-install = true
    

Solution

  • Ugh, I'm leaving this in case anybody else wants to feel embarrassed for themselves.

    The pnpm-workspaces.yml should be named pnpm-workspace.yaml - I'm not sure where I got the other invalid name... but hopefully this helps you waste less time than I did.