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
Exports not found when using absolute import paths based on baseUrl from tsconfig.json or jsconfig.json #2236
Comments
I'm not familiar with This might need a fix here, or it might need one in |
I think that first step should be that someone writes a test which reproduces this problem. |
A short tutorial on how this can be used: https://justinnoel.dev/2019/06/18/configuring-react-absolute-imports-for-typescript/ An example of a publicly viewable React project that uses absolute imports is here: https://github.com/sillsdev/TheCombine/blob/90e2e819cebfbb1a6e9f760ac305f91d6c0b250a/tsconfig.json#L22 {
"compilerOptions": {
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
"downlevelIteration": true,
"baseUrl": "src",
"noFallthroughCasesInSwitch": true
},
"include": [
"src"
]
} My first shot at using Config: "eslintConfig": {
"extends": ["react-app", "plugin:import/recommended", "plugin:import/typescript"],
"env": {
"jest": true
},
"rules": {
"no-undef": "off",
"@typescript-eslint/switch-exhaustiveness-check": "warn"
},
"parser": "@typescript-eslint/parser",
"parserOptions": {
"project": "./tsconfig.json"
},
"settings": {
"import/extensions": [
".js",
".jsx",
".ts",
".tsx"
]
}
}, A full project: https://github.com/sillsdev/TheCombine/tree/sort-ts-imports To reproduce:
Output from CI run: https://github.com/sillsdev/TheCombine/runs/3976722965?check_suite_focus=true |
@johnthagen you also have to define https://github.com/import-js/eslint-plugin-import/blob/main/config/typescript.js#L18-L22 and include the typescript resolver. |
@ljharb Is there an example in the docs that shows how to include the typescript resolver? I couldn't find it in: |
The typescript resolver itself's docs have those instructions: https://www.npmjs.com/package/eslint-import-resolver-typescript |
How does this work with |
That's not a standard thing (just a niche convention), so I would expect that it doesn't work with it. If someone built a custom import plugin resolver for jsconfig.json, then that should work I suppose, but unless babel and bundlers read that file, i'm not sure it'd be a good idea to rely on resolution from it. |
Good to know. The current workaround I'm using is just adding this to my eslint config:
|
You should use https://github.com/import-js/eslint-import-resolver-typescript instead |
Hi,
All my exports from .tsx files are reported as not being used when I use absolute paths based on baseUrl set in tsconfig.json
How to reproduce this problem:
eslint is configured in package.json like this:
Maybe I do something wrong in the way I configure eslint or eslint/eslint-plugin-import has a problem with absolute paths based on baseUrl.
Any help is highly appreciated. Thank you.
Cheers,
Iulian
The text was updated successfully, but these errors were encountered: