-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[import/extensions] 2.22.0 still shows without an extension
error for importing tsx files from tsx files
#1857
Comments
without an extension
error for importing tsx files from tsx files
Add the following rule:
|
Closing this. Hardcoded 2.20.1 for now. Didn't get chance to reproduce. |
I'm going to reopen it; if something broke in a non-major, we need to fix it. |
By adding that, it worked for me, maybe help you as well. |
@asimkt do those settings work for you? |
hey @ljharb, I didn't get a chance to recreate this issue. Busy with office work now. I will try to create one as soon as possible. I went ahead with For future readers who have same issue: Could you please open a sandbox where the issue persists? |
Adding the Above did not help :( |
I can confirm that the error still exists. Seems like you have to do either as @doasync suggested in #1857 (comment) or revert to a previous version. |
I ran into a similar issue (e.g. jsx files not registering with this rule) and adding some settings to the resolver settings fixed the issue: Inside eslint.json: {
"settings": {
"import/resolver": {
"node": {
"extensions": [".js", ".jsx", ".mjs", ".cjs", ".ts", ".tsx"]
}
}
}
} |
I am experiencing this issue as well, but specifically in combination with a path alias. My setup is as following: .eslintrc.json {
"extends": [
"airbnb",
"airbnb/hooks",
"airbnb-typescript"
],
"parserOptions": {
"project": ["./tsconfig.json"]
}
} tsconfig.json {
"compilerOptions": {
"declaration": false,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"lib": ["es6", "dom"],
"module": "es6",
"moduleResolution": "node",
"sourceMap": true,
"target": "es5",
"jsx": "react",
"noEmit": true,
"baseUrl": ".",
"paths": {
"@/*": ["app/javascript/*"]
},
"allowSyntheticDefaultImports": true
},
"exclude": ["node_modules"],
"compileOnSave": false
} Importing something like The issue disappears when I use a different path alias. For example adding My eslint-plugin-import version is |
@eelkevdbos i'm not sure what |
@ljharb, I'm sorry, I thought this was convenient for brevity. I compiled the configuration to json through: {
...
"settings": {
"import/resolver": {
"node": {
"extensions": [
".js",
".jsx",
".json",
".ts",
".tsx",
".d.ts"
]
}
},
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx",
".d.ts"
]
},
"import/extensions": [
".js",
".mjs",
".jsx",
".ts",
".tsx",
".d.ts"
],
"import/external-module-folders": [
"node_modules",
"node_modules/@types"
],
"react": {
"pragma": "React",
"version": "detect"
},
"propWrapperFunctions": [
"forbidExtraProps",
"exact",
"Object.freeze"
],
"import/core-modules": [],
"import/ignore": [
"node_modules",
"\\.(coffee|scss|css|less|hbs|svg|json)$"
]
},
"ignorePatterns": [
"node_modules",
"dist",
"vendor"
]
} On first sight, this seems like a valid configuration. However, without setting This resembles some of the issues that I came across for this project. I was also triggered by the As a bonus weirdness: when I point eslint to the printed configuration, it fails to resolve the import path entirely. Apparently, the printed configuration is not a drop-in replacement for the config file using the "extends" syntax. |
Note how the resolver is set to “node”, and there’s no typescript resolver? That means the eslint config isn’t valid for typescript. |
I've added the .eslintrc.typescript.json {
"plugins": ["import"],
"rules": {
"import/no-unresolved": "error"
},
"settings": {
"import/parsers": {
"@typescript-eslint/parser": [".ts", ".tsx"]
},
"import/resolver": {
"typescript": {}
}
}
} .eslintrc.json {
"extends": [
"airbnb",
"airbnb/hooks",
"airbnb-typescript",
".eslintrc.typescript.json"
],
"parserOptions": {
"project": ["./tsconfig.json"]
}
} With that setup, everything works perfectly! Thanks for the hint 💪 |
I noticed how the starter of this issue also has |
Sounds like that's the solution, then, so I'll close this. You may want to file an issue on airbnb-typescript so they can fix their config (and add the TS resolver as a peer dep) |
Almost like #1615, but getting error on my Github CI which uses the same yarn.lock file.
my lock file:
EDIT
My yarn lock file had eslint-plugin-import@2.20.1 also present. The lint was working fine at my local system.
The text was updated successfully, but these errors were encountered: