Eslint-plugin-import: import/extensions flagging all TypeScript imports w/ 2.19.1

Created on 11 Dec 2019  路  2Comments  路  Source: benmosher/eslint-plugin-import

I'm having an issue where upgrading from 2.18.2 to 2.19.1 has started flagging all TypeScript imports with import/extensions errors, ie.

/Users/andrew/source/####/src/services/####.service.ts
   4:35  error    Missing file extension "ts" for "./helpers/someFile"  import/extensions

These files previously validated correctly with 2.18.2.

One odd thing to note is that I'm using airbnb's preset, which actually sets "import/extensions": ['.js', '.mjs', 'jsx']. Even though .ts and .tsx were missing here, I didn't have this problem until upgrading to 2.19.2. Adding .ts and .tsx to the array has no effect.

This is a lightly-redacted version of my config (generated via eslint --print-config):

{
  "env": {
    "es6": true,
    "node": true,
    "browser": true
  },
  "globals": {},
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2018,
    "ecmaFeatures": {
      "jsx": true,
      "generators": false,
      "objectLiteralDuplicateProperties": false
    },
    "project": "./tsconfig.json",
    "sourceType": "module"
  },
  "plugins": [
    "import",
    "react",
    "jsx-a11y",
    "@typescript-eslint"
  ],
  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never"
      }
    ]
  },
  "settings": {
    "import/resolver": {
      "node": {
        "extensions": [
          ".js",
          ".jsx",
          ".ts",
          ".tsx"
        ]
      },
      "webpack": {}
    },
    "import/extensions": [
      ".js",
      ".mjs",
      ".jsx",
      ".ts",
      ".tsx"
    ],
    "import/parsers": {
      "@typescript-eslint/parser": [
        ".ts",
        ".tsx"
      ]
    },
    "import/core-modules": [],
    "import/ignore": [
      "node_modules",
      "\\.(coffee|scss|css|less|hbs|svg|json)$"
    ]
  }
}
question typescript

Most helpful comment

I think the errors are correct given your ESLint configuration, specifically the options passed to rules.import/extensions:

  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never"
      }
    ]
  },

These files previously validated correctly with 2.18.2.

I think they were _mistakenly_ validated correctly, due to a bug which was fixed recently. (See #1518 and #1521)

To get the behavior you're expecting, you might need to add ts and tsx to the options in the rule config:

  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never",
        "ts": "never",
        "tsx": "never"
      }
    ]
  },

All 2 comments

I think the errors are correct given your ESLint configuration, specifically the options passed to rules.import/extensions:

  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never"
      }
    ]
  },

These files previously validated correctly with 2.18.2.

I think they were _mistakenly_ validated correctly, due to a bug which was fixed recently. (See #1518 and #1521)

To get the behavior you're expecting, you might need to add ts and tsx to the options in the rule config:

  "rules": {
    "import/extensions": [
      "error",
      "ignorePackages",
      {
        "js": "never",
        "mjs": "never",
        "jsx": "never",
        "ts": "never",
        "tsx": "never"
      }
    ]
  },

I agree; this seems like a fixed bug.

Was this page helpful?
0 / 5 - 0 ratings