LoginSignup
0
0

More than 1 year has passed since last update.

Nx Consoleでコロン(:)区切りのスクリプトが認識されない

Posted at

VS Codeの拡張機能のNx Consolelint:fixformat:fixのようなコロン区切りのスクリプトを実行するとコロン以降が消えたスクリプトが実行されるのでメモ。

例)lint:fixを実行する

*  実行するタスク: yarn nx run {project}:lint:fix

yarn run v1.22.18
$ node_modules/.bin/nx run {project}:lint:fix

> nx run {project}:lint  [existing outputs match the cache, left as is]

lint:fixを実行しているにも関わらず、lintが実行されます。

原因

Nx generally uses a colon to delimit nx run {project}:{target}:{configuration}
, so it interprets the command as a target and configuration.

https://github.com/nrwl/nx/issues/9232#issuecomment-1067207447

つまり、今回の例で言うと:fixに当たる部分がtargetではなく、configurationとして認識されるために起こってしまいます。

スクリプトをコマンドラインから実行する場合は、以下のようにすると動きます。

nx run {project}:\"lint:fix\"

ただ、Nx Consoleでは上記のような設定はできません。

解決策

スクリプトをコロン区切りではなく、ハイフン区切りに変更すると直ります。

*  実行するタスク: yarn nx run {project}:lint-fix

yarn run v1.22.18
$ node_modules/.bin/nx run {project}:lint-fix

> nx run {project}:lint-fix  [existing outputs match the cache, left as is]

実際、Nxのpackage.jsonのスクリプトは全てハイフン区切りになっていました。

nx/package.json at master · nrwl/nx

参考

lerna run fails on colon-separated scripts with lerna+Nx
Command nx run project:command does not work if command contains a colon (:)
Make nx run more flexible when using script runner workflow

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0