LoginSignup
2
0

More than 3 years have passed since last update.

ESLint でパッケージからの import は拡張子不要だが、相対パスからの import は拡張子を必要にする場合の設定

Last updated at Posted at 2019-05-25

下記のページを読みながら、ESLint で node_modules 下のパッケージからの import (import express from 'express';)は拡張子不要で、相対パスからの import (import Users from './users.js';) は拡張子必要の設定を試みた。

最初は以下のように設定した。

{
  "rules": {
    "import/extensions": ["error", "ignorePackages"]
  }
}

だが、相対パスの import で拡張子なしのような記載(import Users from './users';)でエラーが起きなかった。

前述のページの一番下の「The following patterns are not considered problems when configuration set to ['error', 'always', {ignorePackages: true} ]:」 の項と、benmosher/eslint-plugin-importIssue #1083をみて、以下のように記載したところ、期待する動作を満たせた。

{
  "rules": {
    "import/extensions": ["error", "always", { "ignorePackages": true }]
  }
}
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