I try run the script from the root but got the error:
ERR! lerna Unknown argument: d
the mand from root package.json:
"start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"
try run yarn start:scripts:api-football:start:collectDayMatches:dev -- -d 2002-02-02
I try run the script from the root but got the error:
ERR! lerna Unknown argument: d
the mand from root package.json:
"start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"
try run yarn start:scripts:api-football:start:collectDayMatches:dev -- -d 2002-02-02
2 Answers
Reset to default 5It seems you are trying to pass mand arguments to the npm script of each package.
For example:
packages/pkg-a/package.json
:
"scripts": {
"start:collectDayMatches:dev": "ls"
}
root package.json
:
"scripts": {
"start:scripts:api-football:start:collectDayMatches:dev": "lerna run start:collectDayMatches:dev --stream"
}
Let's pass the -a
option to the ls
mand.
You should run the npm script with three double-dash (--
) like this:
[main] ⚡ yarn start:scripts:api-football:start:collectDayMatches:dev -- -- -- -a
yarn run v1.22.10
warning From Yarn 1.0 onwards, scripts don't require "--" for options to be forwarded. In a future version, any explicit "--" will be forwarded as-is to the scripts.
$ lerna run start:collectDayMatches:dev --stream -- -- -a
lerna notice cli v3.22.1
lerna info Executing mand in 1 package: "npm run start:collectDayMatches:dev -- -a"
pkg-a: > [email protected] start:collectDayMatches:dev /Users/dulin/workspace/github./mrdulin/lerna-codelab/packages/pkg-a
pkg-a: > ls "-a"
pkg-a: .
pkg-a: ..
pkg-a: app.js
pkg-a: app.test.js
pkg-a: docs
pkg-a: jest.config.js
pkg-a: node_modules
pkg-a: package-lock.json
pkg-a: package.json
lerna success run Ran npm script 'start:collectDayMatches:dev' in 1 package in 0.2s:
lerna success - pkg-a
✨ Done in 0.60s.
As you can see, the final mand is ls "-a"
.
Solution
Add -- -- --
between the lerna mand and the argument you want passed in.
As per the question example...
For the mand:
yarn start:collectDayMatches:dev
add the -- -- --
syntax:
yarn start:collectDayMatches:dev -- -- -- d
(This is the same solution as https://stackoverflow./a/66060685/4930577, but simplified)