2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

<コマンド> failed without output (ENOENT).解消法【husky】【lint-staged】

Posted at

<コマンド> failed without output (ENOENT).解消法

状況

以下の手順でhuskyとlint-stagedを導入し、commit時にeslint --fixprettier --write実行するように設定しました。
パッケージマネージャはyarn3を使用していました。

ターミナル
$ npx mrm@2 lint-staged
package.json
{
  "scripts": {
    ...
    "postinstall": "husky install"
  },
    ...
    "lint-staged": {
    "src/**/*.{js,ts,tsx}": [
      "eslint --fix"
    ],
    "**/*": [
      "prettier --write --ignore-unknown"
    ]
  }
}

.husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

npx lint-staged

git commit -m "test"を実行したところ以下のようにエラーが発生しました。

ターミナル
$ git add .

$ git commit -m "test"
✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ package.json — 1 file
    ↓ src/**/*.{js,ts,tsx} — no files [SKIPPED]
    ❯ **/* — 1 file
      ✖ prettier --write --ignore-unknown [ENOENT]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ prettier --write --ignore-unknown failed without output (ENOENT).
husky - pre-commit hook exited with code 1 (error)

解決方法

.husky/pre-commitを以下のように修正することで解決しました。

.husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn lint-staged

yarnを使用している場合にはnpx lint-stagedではなくyarn lint-stagedとする必要があるようです。

なおyarn dlx lint-stagedと記述しても同様にエラーが発生しました。

.husky/pre-commit
#!/bin/sh
. "$(dirname "$0")/_/husky.sh"

yarn dlx lint-staged
ターミナル
$ git add .

$ git commit -m "test"
➤ YN0000: ┌ Resolution step
➤ YN0000: └ Completed in 2s 468ms
➤ YN0000: ┌ Fetch step
➤ YN0000: └ Completed
➤ YN0000: ┌ Link step
➤ YN0000: │ ESM support for PnP uses the experimental loader API and is therefore experimental
➤ YN0000: └ Completed
➤ YN0000: Done with warnings in 2s 583ms

✔ Preparing lint-staged...
⚠ Running tasks for staged files...
  ❯ package.json — 1 file
    ↓ src/**/*.{js,ts,tsx} — no files [SKIPPED]
    ❯ **/* — 1 file
      ✖ prettier --write --ignore-unknown [ENOENT]
↓ Skipped because of errors from tasks. [SKIPPED]
✔ Reverting to original state because of errors...
✔ Cleaning up temporary files...

✖ prettier --write --ignore-unknown failed without output (ENOENT).
husky - pre-commit hook exited with code 1 (error)

2
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
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?