19
6

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 5 years have passed since last update.

eslint-plugin-importでTypeScriptのimport問題を解決する

Posted at

JavaScript→TypeScript化してる中で詰まったのでメモ。
(JavaScriptとTypeScriptが混在してるプロジェクト)

事象

こういうやつ :point_down:

$ eslint app/javascript/components

/path/to/app/javascript/components/Container/Foo/index.js
  5:25  error  Unable to resolve path to module '../../../Bar'  import/no-unresolved
  5:25  error  Missing file extension for "../../../Bar"        import/extensions

✖ 2 problems (2 errors, 0 warnings)

解決

プラグインを追加して、

yarn add -D eslint-import-resolver-webpack

設定ファイルに追記します。

.eslintrc
{
  "rules": {
+    "import/extensions": [".js", ".jsx", ".json", ".ts", ".tsx"],

...

+  "settings": {
+    "import/resolver": {
+      "webpack": {
+        "config": "webpack.config.js"
+      }
+    }
+  }
} 

以上です :hugging:

参考

19
6
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
19
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?