C:\projects\path\to\code\ReduxDevTools.jsx
6:40 error Missing file extension for "../utilities/cookies" import/extensions
This is the same error I was getting on 2.19.1 (as seen in https://github.com/benmosher/eslint-plugin-import/issues/1558). The error does not appear in 2.18.3.
We're seeing Missing file extension "ts" for ... moving from 2.18.2 to 2.20.0 (refs https://github.com/libero/article-store/pull/174).
I had the same problem with .vue files. I missed this extension in import/resolver settings.
This fixed it for me:
settings: {
'import/resolver': {
node: {
extensions: ['.mjs', '.js', '.json', '.vue'],
},
},
},
Try to replace .vue with .ts
@denisinvader No luck unfortunately (plugin:import/typescript should still be working anyway).
I'm also getting this error when importing .ts files in typescript as well.
Even explicitly changing the settings in my .eslitntrc to include .ts still results in an error:
"settings": {
"import/extensions": [".js", ".mjs", ".jsx", ".js", ".jsx", ".ts", ".tsx"]
},
or setting the rule directly to:
"import/extensions": [
"error",
"always",
{
"ts": "never",
"tsx": "never",
"js": "never",
"jsx": "never"
}
],
@maclockard It seems like settings['import/extensions'] doesn't work (or logic has changed) after 2.18 and you should use correct import/resolver config.
Do you use typescript resolver?
I had to update config after the package upgrade and add the resolver for webpack but now my linter works much better and can understand aliased imports like @/components/...
Unfortunately, I have zero experience in typescript so my suggestions are more assumptions
Nevermind, this is working correctly for when I set this in the rules:
'import/extensions': ['error', 'ignorePackages', {
js: 'never',
mjs: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
}],
and set this in the settings:
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json']
}
},
I believe in 2.18.3 it wasn't reporting errors that it should have been reporting based on my config (I was not overriding the default import/extensions that is used in airbnb which only allows for normal JavaScript files).
To clarify, when using airbnb-base and plugin:import/typescript you still need to include the import/extensions rule yourself?
@thewilkybarkid I think you still need to override import/extensions in the rules section, not just the settings section. I don't know if that's intentional or not.
The airbnb config doesn't include typescript extensions, so yes, you need to override both.
plugin:import/typescript seems to cover settings; could rules be added there too to cover it?
Tested locally and that works, so opened https://github.com/benmosher/eslint-plugin-import/pull/1637.
Hello @thewilkybarkid ! Is your change already in the codebase? I see it was committed however I still get this error. I use "eslint-plugin-import": "^2.20.1"
@javierguzman It was closed rather than committed (see https://github.com/benmosher/eslint-plugin-import/pull/1637#pullrequestreview-351678384). For my case I'm switching to using eslint-config-airbnb-typescript rather than eslint-config-airbnb-base directly.
@thewilkybarkid Thanks! I will keep that package in mind, I think for now I will stick with specifying the never rule thing mentioned above...
Nevermind, this is working correctly for when I set this in the
rules:'import/extensions': ['error', 'ignorePackages', { js: 'never', mjs: 'never', jsx: 'never', ts: 'never', tsx: 'never', }],and set this in the
settings:'import/resolver': { node: { extensions: ['.js', '.jsx', '.ts', '.tsx', '.json'] } },I believe in 2.18.3 it wasn't reporting errors that it should have been reporting based on my config (I was not overriding the default
import/extensionsthat is used in airbnb which only allows for normal JavaScript files).
I got the same problem with .vue file and it took me a whole day, read every single thread about these 2 rules (import/extensions and import/no-unresolved), and still got errors.
after trying your setting, it works like a charm, and I still have no idea why :-|
here are my .eslintrc.js file
rules: {
//...
'import/extensions': [
'error',
'ignorePackages',
{
js: 'never',
mjs: 'never',
jsx: 'never',
ts: 'never',
tsx: 'never',
vue: 'never',
},
],
},
settings: {
'import/resolver': {
node: {
extensions: ['.js', '.jsx', '.ts', '.tsx', '.json', '.vue'],
},
},
},
@Methuselah96 - are you still having this issue for 2.22.0? I am still seeing issue.
@lvdang No, I posted the solution above: https://github.com/benmosher/eslint-plugin-import/issues/1615#issuecomment-577500405.
Most helpful comment
Nevermind, this is working correctly for when I set this in the
rules:and set this in the
settings:I believe in 2.18.3 it wasn't reporting errors that it should have been reporting based on my config (I was not overriding the default
import/extensionsthat is used in airbnb which only allows for normal JavaScript files).