beachball
beachball copied to clipboard
Error running "check" when beachball not installed at the root of the git repo
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
Applying these two workarounds helped me get past this error:
- Add a
beachball.conf.js
that setsbranch
to the name of my mainline (e.g.origin/main
). This preventsworkspace-tools
from trying to learn this info from the git root. - add
workspaces: []
to mypackage.json
. Thepackage.json
was actually an Angular workspace, not a NPM workspace, so it was missing this field. The beachball functionfindProjectRoot()
calls into code inworkspace-tools
which uses this field as the indication that it found the correctpackage.json