最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - can`t pass command line args using lerna - Stack Overflow

programmeradmin1浏览0评论

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

Share Improve this question edited Mar 9, 2021 at 14:27 RobC 25k21 gold badges84 silver badges85 bronze badges asked Apr 29, 2020 at 6:14 Edgaras KarkaEdgaras Karka 7,85217 gold badges68 silver badges120 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 5

It 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)

发布评论

评论列表(0)

  1. 暂无评论