beachball icon indicating copy to clipboard operation
beachball copied to clipboard

Error running "check" when beachball not installed at the root of the git repo

Open jattasNI opened this issue 3 years ago • 1 comments

I have a git repo where the NPM workspace that uses beachball is not at the git root:

my-repo/
├─ .git
├─ web/
│  ├─ package.json   <-- contains beachball as devDependency and "check": "beachball check" in the scripts section
│  ├─ package-lock.json
│  ├─ node_modules/

When I run npm run check from the web directory, I get the following error:

> beachball check

beachball v2.21.0 - the sunniest version bumping tool
An error has been detected while running beachball!
Error: invalid package.json detected
    at getDefaultRemote (/my-repo/web/node_modules/workspace-tools/lib/git.js:402:15)
    at Object.getDefaultRemoteBranch (/my-repo/web/node_modules/workspace-tools/lib/git.js:367:27)
    at Object.getRepoOptions (/my-repo/web/node_modules/beachball/lib/options/getRepoOptions.js:34:52)
    at Object.getOptions (/my-repo/web/node_modules/beachball/lib/options/getOptions.js:12:117)
    at /my-repo/web/node_modules/beachball/lib/cli.js:22:34
    at Generator.next (<anonymous>)
    at /my-repo/web/node_modules/beachball/lib/cli.js:8:71
    at new Promise (<anonymous>)
    at __awaiter (/my-repo/web/node_modules/beachball/lib/cli.js:4:12)
    at /my-repo/web/node_modules/beachball/lib/cli.js:21:8

The problem appears to be that beachball (or workspace-tools) is expecting a package.json to exist at the root of my-repo, next to .git.

I believe this is meant to be a supported use case, given that similar issues have been fixed in the past: #439

The only workaround I've found is to install and run beachball from the git root, as described in #340

jattasNI avatar Jan 28 '22 16:01 jattasNI

Applying these two workarounds helped me get past this error:

  1. Add a beachball.conf.js that sets branch to the name of my mainline (e.g. origin/main). This prevents workspace-tools from trying to learn this info from the git root.
  2. add workspaces: [] to my package.json. The package.json was actually an Angular workspace, not a NPM workspace, so it was missing this field. The beachball function findProjectRoot() calls into code in workspace-tools which uses this field as the indication that it found the correct package.json

jattasNI avatar Jan 28 '22 23:01 jattasNI