eslintコマンドを実行した際に発生した 「"path" argument must be of type string. Received an instance of Array」エラーの対処

ESLintエラー解消
eslintコマンドを実行した際に発生した 「"path" argument must be of type string. Received an instance of Array」エラーの対処
Memo
この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

eslintコマンドを実行した際に発生する "path" argument must be of type string.エラーの対処についてメモしました。

経緯

reactとmobx-state-treeを利用しているプロジェクトがあり
そのプロジェクトのパッケージを最新にアップデートしリントチェックしたところ発生しました。

環境

  • Yarn 1.22.4
  • Node.js 14.15.3
  • eslint 7.29

発生したエラー

yarn eslint --fixコマンドを実行するとエラーになりリントが動かないという状況が発生しました。

terminal
$ yarn eslint --fix src/**/*.tsx yarn run v1.22.10 $ /Users/XXXX/project/node_modules/.bin/eslint --fix src/**/*.tsx Oops! Something went wrong! :( ESLint: 7.29.0 TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Array at validateString (internal/validators.js:124:11) at Object.isAbsolute (path.js:1029:5) at isFilePath (/Users/XXXX/project/node_modules/@eslint/eslintrc/lib/config-array-factory.js:131:14) at /Users/XXXX/project/node_modules/@eslint/eslintrc/lib/config-array-factory.js:905:17 at Array.reduce (<anonymous>) at ConfigArrayFactory._loadPlugins (/Users/XXXX/project/node_modules/@eslint/eslintrc/lib/config-array-factory.js:904:22) at ConfigArrayFactory._normalizeObjectConfigDataBody (/Users/XXXX/project/node_modules/@eslint/eslintrc/lib/config-array-factory.js:725:44) at _normalizeObjectConfigDataBody.next (<anonymous>) at ConfigArrayFactory._normalizeObjectConfigData (/Users/XXXX/project/node_modules/@eslint/eslintrc/lib/config-array-factory.js:665:20) at _normalizeObjectConfigData.next (<anonymous>) error Command failed with exit code 2. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

エラーについて

エラーの内容はパスは文字列型を指定する必要があるというエラーです。

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received an instance of Array

ファイルなどが明示されている通常のlintのエラーではなかったため悩みました。

原因

mobxのデコレーター(@XXXみたいな書き方)を利用するのに必要な @babel/plugin-proposal-decorators プラグインの設定が
なぜかeslint設定ファイルのpluginへ記載されていたことが原因でした。

eslintrc.js
module.exports = { plugins: [ ["@babel/plugin-proposal-decorators", { legacy: true }], ], }

プラグインの設定を削除して解決

原因の部分の下記を削除して解決しました。

eslintrc.js
module.exports = { plugins: [ ["@babel/plugin-proposal-decorators", { legacy: true }], ], }

そもそもなぜ@babel/plugin-proposal-decoratorsの設定がeslintrcにあったかの確認(.babelrcと設定を間違えた?)が必要だなと思ったのと、オブジェクトが渡っていたことでパスのエラーが出ていたと理解しました。

終わりに

最後までご覧いただきありがとうございます。
この記事ではeslintコマンドを実行した際に発生した 「"path" argument must be of type string. Received an instance of Array」エラーの対処について紹介させていただきました。

これからも皆様の開発に役立つ情報を提供していきたいと考えています。
今後ともよろしくお願いいたします。