berry: [Bug?]: yarn workspaces focus command fails in ^3.0.0-rc

Self-service

  • I’d be willing to implement a fix

Describe the bug

When running the command yarn workspaces focus <pkg> in 3.0-rc versions

Type Error: e.every is not a function
    at test (/frontend/.yarn/releases/yarn-3.0.0-rc.9.cjs:10:36984)

To reproduce


const path = require(`path`);
const {promises: {mkdir, readFile, writeFile, writeJson}} = require(`fs`);

await packageJsonAndInstall({
  "name": "root",
  "private": true,
  "workspaces": [
    "packages/*"
  ]
});


/* create an app module*/

await mkdir('packages/lib', { recursive: true });

await writeFile("packages/lib/package.json", `{
  "peerDependencies": {
    "lodash": "^4.0.0"
  },
  "main": "index.js",
  "name": "lib",
  "version": "0.0.1"
}`);

const version = await yarn('--version');
console.log('version', version);

await yarn(`install`);

await expect(yarn(`workspaces`, `focus`, `lib`)).rejects.not.toThrow();

Environment

System: OS: macOS 11.4 CPU: (4) x64 Intel® Core™ i5-7500 CPU @ 3.40GHz Binaries: Node: 14.2.0 Yarn: 3.0.0-rc.9

Additional context

It seems to be throwing from the typanion package

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 23 (6 by maintainers)

Commits related to this issue

Most upvoted comments

You need to update the plugins you’re using as well when you update the CLI

The specific fix for this:

yarn plugin import @yarnpkg/plugin-workspace-tools

Highly recommend running the same for all your plugins listed in your .yarnrc.yml

Just wanted to add another experience of this issue. After updating yarn to 3.2.x in our monorepo, all workspace foreach commands worked as expected locally but three of them failed on CI.

Based on some of the very helpful description in this comment, we were able to deduce that the arguments to the workspaces foreach was the cause of the issue.

// fails in CI with 'Invalid Command Schema' error from typanion.
yarn workspaces foreach -pvi --exclude vuepress run lint

// runs normally in CI:
yarn workspaces foreach -pvi run lint

Great, I’ll close this again then 👍

Since .yarn/ was in our cache and the plugins use the same file name regardless of version, we ended up checking out the v3 plugins, then immediately overwriting them every time with the old v2 plugins.

When updating from v2 to v3 the yarn.lock file changed so your cache should have been invalidated, out of curiosity, what was your cache key set to?

Yeah, I’m talking specifically about the cache available in gitlab runners: https://docs.gitlab.com/ee/ci/caching/. We had configured the runner to zip up the whole .yarn/ directory and send it off to a blob storage. Then when the next job of that type ran, after git checkout, it downloaded and unzipped the “cache” from the blob store. There’s no cache key really. Sort of a blunt instrument. We just disabled the whole thing. yarn’s zero install stuff is better and we hadn’t really been using it since we switched over to berry and started really using the zero install stuff. So it was just dirtying up the workspace and taking time and energy zipping up, pushing, and pulling archives that were totally useless. 🤦‍♂️

@noseworthy Aha, thank you! Bad cache invalidation turned out to be my issue as well! I’ve added .yarnrc.yml to my cache paths so the old cache will get invalidated properly next time on new Yarn releases. Now everything is working great both locally and on Github Actions! I’m good with this ticket being closed out! Thank you everyone for your time!

Is there any extra information that would be helpful?

A reproduction would be highly appreciated, only way I can reproduce this is to use Yarn v3 with v2 plugins

yarn set version berry
yarn set version 3.0.2
yarn plugin import workspace-tools@2.2.0
yarn workspaces focus
Type Error: e.every is not a function
   at test (~/.node/corepack/yarn/3.0.2/yarn.js:10:36997)
   at l.validateAndExecute (~/.node/corepack/yarn/3.0.2/yarn.js:197:527)
   at async ts.run (~/.node/corepack/yarn/3.0.2/yarn.js:211:1846)
   at async ts.runExit (~/.node/corepack/yarn/3.0.2/yarn.js:211:2013)
   at async i (~/.node/corepack/yarn/3.0.2/yarn.js:310:12327)
   at async i (~/.node/corepack/yarn/3.0.2/yarn.js:310:11356)
   at async r (~/.node/corepack/yarn/3.0.2/yarn.js:310:10567)

Hey @merceyz! Thanks for re-opening. I’ve been trying to reproduce all day so I could get that to you, but unfortunately I was only able to reproduce with v2 plugins as you said. However on our CI/CD system running on GitLab pipelines this failed every time for our main branch.

After a whole bunch of debugging we’ve discovered that it was some caching that we were doing in the pipeline that was causing this to fail. We were caching the .yarn/ directory and re-using it between builds. The order of operations in our pipelines was:

  1. check out repo
  2. download and unpack cache
  3. run pipeline steps

Since .yarn/ was in our cache and the plugins use the same file name regardless of version, we ended up checking out the v3 plugins, then immediately overwriting them every time with the old v2 plugins. We’ve since fixed up our caching strategy and everything works as expected now on our end. Sorry for the noise on this one, though it does seem that @jalovatt and @davidcalhoun are still experiencing issues. Maybe this little post-mortem helps?

Thanks again for your work on this project. Yarn is wonderful ❤️

Hey, @merceyz and @AlexandreBonaventure! Since it seems like this issue isn’t resolved. Should this issue be re-opened or should I create a new issue? Is there any extra information that would be helpful? Thanks for your work on this project!

@jalovatt, did you manage to get it working after?

Nope. We’re sticking to v2 for the moment.

I’m seeing the same error in our CI on 3.0.1 even after updating my plugins. It works when run locally, though. 😕

> root@ start:test /builds/project
> yarn workspaces foreach -pvi --include @project/client --include @project/graphql --include @project/screenshot run start:test
Type Error: e.every is not a function
    at test (/builds/project/.yarn/releases/yarn-3.0.1.cjs:10:36997)
    at g.validateAndExecute (/builds/project/.yarn/releases/yarn-3.0.1.cjs:197:527)
    at async ts.run (/builds/project/.yarn/releases/yarn-3.0.1.cjs:211:1846)
    at async ts.runExit (/builds/project/.yarn/releases/yarn-3.0.1.cjs:211:2013)
    at async i (/builds/project/.yarn/releases/yarn-3.0.1.cjs:310:12327)
    at async i (/builds/project/.yarn/releases/yarn-3.0.1.cjs:310:11356)
    at async r (/builds/project/.yarn/releases/yarn-3.0.1.cjs:310:10567)
// yarnrc.yml

nodeLinker: node-modules

plugins:
  - path: .yarn/plugins/@yarnpkg/plugin-workspace-tools.cjs
    spec: "@yarnpkg/plugin-workspace-tools"
  - path: .yarn/plugins/@yarnpkg/plugin-version.cjs
    spec: "@yarnpkg/plugin-version"

yarnPath: .yarn/releases/yarn-3.0.1.cjs