Search code examples
next.jsversioningmonorepoyarn-workspaces

yarn monorepo with multiple versioning files, fix yarn version check or reset


Given the following state of my NextJS monorepo app:

  • monorepo with multiple private packages managed via yarn workspaces
  • develop is default branch, testing environment and has multiple commits ahead of main
  • main branch has fewer commits and only those ready for staging environment
  • commits to main are pushed via PRs with cherry-picking from develop
  • develop versioning of those private monorepo packages is all green (the yarn version check command)
  • version checking is disabled PR-level and branch level on main and due to cherry-picking/reverts/squash/etc. the yarn version check fails on the main branch with the following error:
yarn version check
➤ YN0001: UsageError: Your current branch contains multiple versioning files; this isn't supported:
- /Users/tbutcaru/Projects/my-nextjs-app/.yarn/versions/00648a82.yml
- /Users/tbutcaru/Projects/my-nextjs-app/.yarn/versions/009a6542.yml
- /Users/tbutcaru/Projects/my-nextjs-app/.yarn/versions/018f7b67.yml
- /Users/tbutcaru/Projects/my-nextjs-app/.yarn/versions/0197a805.yml
    at h (/Users/tbutcaru/Projects/my-nextjs-app/.yarn/plugins/@yarnpkg/plugin-version.cjs:5:3539)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
....
  • the mentioned .yarn/versions/... files do not exist in my main branch.

Same issue here and here - closed without solution. I've already tried what others have said through comments in the mentioned links.

I've tried:

  • yarn version apply --all
  • yarn version check --interactive
  • upgrade to latest yarn 3.4.0 (using 2.4.2 right now)
  • deleted all .yarn/versions file dir + yarn.lock and reinstall all packages
  • manually bump all private packages versions
  • copy the .yarn/versions file dir from develop to main
  • added changesetIgnorePatterns: - '.yarn/**/*' in the .yarnrc.yml file and I no longer get the error above but the following YN0000: @my-nextjs-app/shared-components@workspace:packages/shared-components has been modified but doesn't have a release strategy attached and I've run the yarn version check --interactive, so the package has a release strategy attached, but still the yarn version check fails.

... none of the above worked.

How can I fix the "multiple versioning files" issue? Or, at least, how do I completely reset/reinit the yarn workspace packages versions on the main branch?

Thank you!


Solution

  • I didn't find any solution to my issue with the initial setup described in the original post, but I've manage to fix the yarn version check --interactive with a .yarnrc.yml config change!

    I'll try to provide a bit more context on the issue and solution.

    Recently I've changed my repo's default branch from develop to main and that's how I've ended up with the issue above. The idea behind the default branch switch was to move to main and archive develop forever and that created a task of removing all codebase and configs related to develop.

    So, while working on removing any develop branch leftovers from my repo, I've reached to .yarnrc.yml which had the following config:

    changesetBaseRefs:
      - develop
      - origin/develop
      - upstream/develop
    

    ... changing it to:

    changesetBaseRefs:
      - main
      - origin/main
      - upstream/main
    

    ... resulted in yarn version check --interactive and yarn version check to work!