-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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
eslint-config-next should support absolute imports #25920
Comments
Thanks for logging this @stefanprobst Just to clarify, wouldn't this be possible by locally extending
Or would you prefer that Next.js supports this by default to match all absolute paths that are set within |
hi @housseindjirdeh , thank you for all your work on eslint integration in next! personally, i'd prefer to integrate with here`s my "user story":
+ "baseUrl": ".",
+ "paths": {
+ "@/*": ["src/*"],
+ "~/*": ["*"]
+ }
- "extends": ["next", "next/core-web-vitals"]
+ "extends": ["plugin:import/recommended", "next", "next/core-web-vitals"]
mkdir src && mv pages styles src
import styles from '../styles/Home.module.css'
import styles from "@/styles/Home.module.css";
{
"extends": ["plugin:import/recommended", "next", "next/core-web-vitals"],
+ "settings": {
+ "import/resolver": {
+ "node": {
+ "moduleDirectory": ["node_modules", "src/"]
+ }
+ }
+ }
}
- import styles from "@/styles/Home.module.css";
+ import styles from "styles/Home.module.css";
yarn add -D @types/unist
import type { Node } from "unist";
yarn add -D eslint-import-resolver-typescript
"settings": {
"import/resolver": {
- "node": {
- "moduleDirectory": ["node_modules", "src/"]
- }
+ "typescript": {}
}
}
"import/resolver": {
"typescript": {
+ "alwaysTryTypes": true
}
}
|
Thank you for all the amazing feedback. Have appreciated each and every one :) Wow thank you so much for going into so much detail explaining the exact issue. Definitely see the concern of trying to wrangle with absolute imports defined in TS config. Just added |
nice! when setting both |
Looks like the first resolver that successfully resolves is always the source of truth per the docs. Should |
Also closing this in lieu of #26280, but can re-open if things still need to be tweaked 🙏 |
my only concern was a potentional perf impact, because for absolute imports now both resolvers will run (first node, which cannot find it, then typescript). but i did a small unscientific benchmark (here), and it seems the impact is negligible - so 👍. |
Awesome, thanks for doing a quick perf test and for all the feedback mate :) |
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
What version of Next.js are you using?
10.2.4-canary.9
What version of Node.js are you using?
14
What browser are you using?
Firefox
What operating system are you using?
Ubuntu
How are you deploying your application?
n/a
Describe the Bug
eslint-config-next
includeseslint-plugin-import
witheslint-import-resolver-node
, which does not support absolute imports (set viatsconfig.json#paths
).this is not an issue in the default next eslint config, because it only enables the
no-anonymous-default-export
rule, but becomes apparent as soon as a user extendsplugin:import/recommended
or adds any import-related rules fromeslint-plugin-import
.possible solution would be to use
eslint-import-resolver-typescript
Expected Behavior
default next eslint config should be set up to work with absolute imports (tsconfig paths)
To Reproduce
happy to provide a repro if necessary
The text was updated successfully, but these errors were encountered: