yarn publish does not work as expected on mono-repo with lerna

Created on 8 Feb 2018  路  4Comments  路  Source: yarnpkg/yarn

Do you want to request a feature or report a bug?

Report a bug

What is the current behavior?
yarn publish command cannot handle mono-repo like (jest)[https://github.com/facebook/jest] correctly.

For this kind of mono-repo, private field in package.json of project root is set to true. However, when to execute yarn publish script, yarn complains this is a private package:

error An unexpected error occurred: "Package marked as private, not publishing.".

However, if I change the script name from publish to lerna-publish, then execute yarn lerna-publish, the same publish script is executed without complaints.

If the current behavior is a bug, please provide the steps to reproduce.

  1. For a mono repo project like (jest)[https://github.com/facebook/jest] whose root package.json private field is set to true. A publish script cmd using lerna is in the package.json.
  2. Execute yarn publish will complain and reject publish.
  3. Change the script publish into something like lerna-publish again, then execute can publish all packages.

What is the expected behavior?
Not complain root package.json private true scenario for mono-repo with lerna.

Please mention your node.js, yarn and operating system version.
OS: Ubuntu 16.04.3 LTS
Yarn: 1.4.1-20180130.1215 (Nightly build)
Node: 8.9.4

triaged

Most helpful comment

@rosskevin I think @arcanis 's point is that if you run yarn publish in the root of the monorepo, then yarn will try to publish the root of the monorepo to the npm registry, because yarn publish is a normal yarn command. It does not _just_ run your publish script, which I assume is something like:

"scripts": {
  "publish": "lerna publish"
}

Yarn will execute it's own internal publish command. Only if a command with that name does not exist will it fall back to checking for a scripts with a matching name. (however you could call yarn run publish and execute your script)

It also doesn't call publish in each of the individual packages (just like yarn add in the root of the monorepo doesn't call yarn add in every monorepo package)

I do see your point though that yarn publish in a workspace/monorepo configuration should probably not try to "publish" the root of the monorepo. In this case exiting with an error is probably correct, because you shouldn't publish the root of a monorepo, but the message could be a lot more helpful.
I was caught off guard the first time I ran yarn publish in my monorepo expecting it to "publish" each individual package and instead saw an error.

All 4 comments

Running yarn publish does not run the publish script from your package.json (or rather, it doesn't only do that). It's an actual builtin command that submits the local package to the npm registry. Since the local package is defined as being private, we abort.

@arcanis only the root package.json that executes lerna is marked as private, the package of the project itself is not marked private.

Do you have a minimal repo I can use to reproduce this issue?

@rosskevin I think @arcanis 's point is that if you run yarn publish in the root of the monorepo, then yarn will try to publish the root of the monorepo to the npm registry, because yarn publish is a normal yarn command. It does not _just_ run your publish script, which I assume is something like:

"scripts": {
  "publish": "lerna publish"
}

Yarn will execute it's own internal publish command. Only if a command with that name does not exist will it fall back to checking for a scripts with a matching name. (however you could call yarn run publish and execute your script)

It also doesn't call publish in each of the individual packages (just like yarn add in the root of the monorepo doesn't call yarn add in every monorepo package)

I do see your point though that yarn publish in a workspace/monorepo configuration should probably not try to "publish" the root of the monorepo. In this case exiting with an error is probably correct, because you shouldn't publish the root of a monorepo, but the message could be a lot more helpful.
I was caught off guard the first time I ran yarn publish in my monorepo expecting it to "publish" each individual package and instead saw an error.

Was this page helpful?
0 / 5 - 0 ratings