Skip to content

Publishing with yarn doesn't work correctly #1454

@bensampaio

Description

@bensampaio

Affected Packages

@changesets/cli

Problem

Publishing with yarn should be done via yarn npm publish but @changesets/cli is using npm publish instead. This means some workspaces features that are yarn specific do not work as expected. For instance, when publishing with yarn npm publish yarn replaces inner packages with version workspace:^ with the correct version. While when publishing with npm publish npm ignores packages with version workspace:^. This results in incorrectly published packages because when installing it package managers won't be able to resolve workspace:^.

I believe the above is also the reason why .yarnrc.yml is ignored when publishing via changesets.

This is simple to reproduce:

  1. In a monorepo managed by yarn create packages "@example/a" and "@example/b".
  2. The package.json of @example/a contains @example/b as a dependency:
"dependencies": {
  "@example/b": "workspace:^"
}
  1. Create a changeset for @example/a.
  2. Generate the new versions via changeset version.
  3. Then publish via changeset publish.
  4. Now install the new version in a new project and check the package.json in the node_modules and also the new info added to yarn.lock. You'll see workspace:^ hasn't been replaced.

Related issues:

Proposed solution

The proposed solution is to use yarn npm publish instead of npm publish. I tested this out in a private monorepo and it works. I also opened a PR for this change here and would like help getting it reviewed and approved.

This issue is pretty urgent for us at my company. Any guidance on how to move this forward would be very much appreciated.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions