mysticatea / npm-run-all

A CLI tool to run multiple npm-scripts in parallel or sequential.
MIT License
5.72k stars 240 forks source link

Stopped working with `yarn` #196

Open nfantone opened 3 years ago

nfantone commented 3 years ago

While having the following scripts on package.json:

    "clean": "rimraf es lib dist",
    "build:es": "cross-env BABEL_ENV=es babel src/ --out-dir es",
    "build:cjs": "cross-env BABEL_ENV=commonjs babel src --out-dir lib",
    "build:umd": "rollup -c",
    "build": "npm-run-all clean --parallel build:*",

running npm run build works fine and does exactly what is expected. Using yarn, however, fails with a bunch of exceptions.

❯ yarn build
yarn run v1.22.10
$ npm-run-all clean --parallel build:*
Watching /path/to/project and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./.git ; is listed in .gitignore
Found & ignored ./.github ; is listed in .gitignore
Found & ignored ./docs ; is listed in .gitignore
Found & ignored ./node_modules ; is listed in .gitignore
Found & ignored ./src ; is listed in .gitignore
Found & ignored ./CHANGELOG.md ; is listed in .gitignore
Found & ignored ./LICENSE ; is listed in .gitignore
Found & ignored ./README.md ; is listed in .gitignore
Found & ignored ./babel.config.js ; is listed in .gitignore
Found & ignored ./index.js ; is listed in .gitignore
Found & ignored ./jsdoc.json ; is listed in .gitignore
Found & ignored ./package.json ; is listed in .gitignore
Found & ignored ./rollup.config.js ; is listed in .gitignore
Found & ignored ./yarn.lock ; is listed in .gitignore

Starting: clean
internal/modules/cjs/loader.js:883
  throw err;
  ^

Error: Cannot find module '/path/to/project/clean'
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
    at internal/main/run_main_module.js:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Interestingly, this only seems to happen if scripts include run-s, run-p or npm-run-all calls. For instance, running simply yarn clean (which invokes rimraf) works, but running yarn run-s clean fails with the same exception shown above.

Using:

❯ node -v
v14.15.4

❯ yarn -v
1.22.10

❯ npm -v
7.4.0
TreTuna commented 3 years ago

It's due to the glob pattern. Yarn is expanding the glob and not sending it to npm-run-all. If you wrap the glob in quotes, it should work.

    "build": "npm-run-all clean --parallel 'build:*'",

See also: https://github.com/mysticatea/npm-run-all/issues/200

nfantone commented 3 years ago

@TreTuna It's been a while since I posted this, so I cannot truly confirm what you're saying. But judging from my original comments, that wouldn't explain why yarn run-s clean (which does not set any glob patterns) doesn't work.

Also, the issue you're pointing at is related to yarn v2. My issue is reproducible in 1.22.10.

snejugal commented 3 years ago

The error is very similar to mine, except that I'm getting it with npm@7.8.0 (that is, without yarn at all), but on npm@6.14 it works fine:

$ npm --version
7.8.0
$ npm run build:cat

> coreutils@0.0.0 build:cat
> cd src/uu/cat && wasm-pack build && npx pkg2wef

# ...executes successfully

$ npx npm-run-all build:cat
Watching /home/snejugal/projects/wubix-crates/coreutils and all sub-directories not excluded by your .gitignore. Will not monitor dotfiles.
Found & ignored ./node_modules ; is listed in .gitignore

Starting: build:cat
node:internal/modules/cjs/loader:928
  throw err;
  ^

Error: Cannot find module '/home/snejugal/projects/wubix-crates/coreutils/build:cat'
    at Function.Module._resolveFilename (node:internal/modules/cjs/loader:925:15)
    at Function.Module._load (node:internal/modules/cjs/loader:769:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:76:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}
^C # note: it doesn't exit but stuck in some infinite loop wasting CPU time
$ npx npm-run-all --version
v4.1.5
$ npm i -g npm@6

removed 58 packages, changed 11 packages, and audited 436 packages in 6s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
$ npm --version
6.14.12
$ npx npm-run-all build:cat

> coreutils@0.0.0 build:cat /home/snejugal/projects/wubix-crates/coreutils
> cd src/uu/cat && wasm-pack build && npx pkg2wef

# ...executes successfully as well

$ npx npm-run-all --version
v4.1.5

FWIW, the repo is public: https://gitlab.com/wubix-crates/coreutils (note that if you try to execute npm run build, it's going to compile Rust code to WASM, so for reproduction getting an error like wasm-pack: command not found is enough)

petermikitsh commented 3 years ago

I ran into this issue with Yarn Classic (v1) and the workaround was to downgrade from npm v7 to npm v6:

npm i -g npm@6
jamesrweb commented 3 years ago

@petermikitsh worked for me too, any idea why the downgrade is even a solution though?

kjk7034 commented 3 years ago

change from

"build": "npm-run-all clean --parallel build:*",

to

"build": "npm-run-all clean --parallel 'build:*'",