npm-run-all icon indicating copy to clipboard operation
npm-run-all copied to clipboard

Glob matching does not work when specified in script using Yarn 2

Open Robin-Hoodie opened this issue 3 years ago • 9 comments

Running a script echo: run-p echo:* defined in package.json will not work on Yarn 2.

Example package.json:

{
  "name": "test-yarn1",
  "version": "1.0.0",
  "main": "index.js",
  "license": "MIT",
  "scripts": {
    "echo:bar": "echo 'bar'",
    "echo:foo": "echo 'foo'",
    "echo": "run-p echo:*"
  },
  "devDependencies": {
    "npm-run-all": "^4.1.5"
  }
}

To reproduce:

  • Create a dir
  • Run yarn init -y
  • Run yarn add -D npm-run-all
  • Add 3 scripts to package.json:
    • "echo:foo": "echo 'foo'"
    • "echo:bar": "echo 'bar'"
    • "echo": "run-p echo:*"
  • Run yarn set version berry
  • Run yarn echo

=> No matches found: "echo:*"

Oddly enough, running yarn run-p echo:* directly does still work

Reproduction repo: https://github.com/Robin-Hoodie/yarn2-npm-run-all-repro

Robin-Hoodie avatar Feb 20 '21 13:02 Robin-Hoodie

I just ran into this myself. If you quote the * then yarn won't try to handle the wildcard and run -p will work as expected.

Try this:

  "scripts": {
    "echo:bar": "echo 'bar'",
    "echo:foo": "echo 'foo'",
    "echo": "run-p 'echo:*'"
  }

nigelzor avatar Feb 20 '21 19:02 nigelzor

Thanks for the tip, that works!

I do think the root cause of this should be fixed however (whether here or in Yarn 2) If not that, at minimum some documentation can be added

Robin-Hoodie avatar Feb 21 '21 08:02 Robin-Hoodie

I ended up falling for that too. Please add it to the documentation

arthurfiorette avatar Oct 13 '21 21:10 arthurfiorette

I don't think this is a bug for both sides. Please don't get mad at me; I was also confused by the error. However, * is a valid shell syntax for globs, and Yarn implements a bash-like shell that presumably expands the wildcard.

It seems like expanding the wildcard is the expected behaviour of Yarn, and it doesn't look like npm-run-all can solve it either.

BasixKOR avatar Feb 07 '22 21:02 BasixKOR

I just ran into this myself. If you quote the * then yarn won't try to handle the wildcard and run -p will work as expected.

Try this:

  "scripts": {
    "echo:bar": "echo 'bar'",
    "echo:foo": "echo 'foo'",
    "echo": "run-p 'echo:*'"
  }

Thanks very much for this. I had to line up all related script commands on one line as I didn't know what to do.

waptik avatar Apr 21 '22 10:04 waptik

Hey, just had the issue too.

it doesn't look like npm-run-all can solve it either.

Agree, but adding it to the doc could be a good help, it avoids people to look for this issue 🙂.

mathieutu avatar Sep 09 '22 12:09 mathieutu

Ditto to all of the above. Thank goodness for github issues and threads like these. This was the first thing that broke when I updated to yarn 2, given that the docs say it will work with yarn this was a little confusing to find the solution here.

BensThoughts avatar Sep 10 '22 06:09 BensThoughts

Adding double quotes works for me in Yarn 4.0.0-rc.27:

  "scripts": {
    "echo:bar": "echo \"bar\"",
    "echo:foo": "echo \"foo\"",
-   "echo": "npm-run-all echo:*"
+   "echo": "npm-run-all \"echo:*\""
  }

Otherwise, it says No matches found: "echo:*". Using double quotes for compatibility with cmd.exe.

kachkaev avatar Nov 05 '22 18:11 kachkaev

I find it odd that this works for all the other manager packages (npm, yarn classic, pnpm, bun), but not for modern Yarn. 😅

Thanaen avatar Nov 13 '23 10:11 Thanaen