javascriptyarnpkglerna

can`t pass command line args using lerna


I try run the script from the root but got the error:

ERR! lerna Unknown argument: d

the command 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


Solution

  • It seems you are trying to pass command 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 command.

    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 command in 1 package: "npm run start:collectDayMatches:dev -- -a"
    pkg-a: > pkg-a@1.0.0 start:collectDayMatches:dev /Users/dulin/workspace/github.com/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 command is ls "-a".