Skip to content

Exports not found when using absolute import paths based on baseUrl from tsconfig.json or jsconfig.json #2236

Closed as not planned

Description

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:

  1. npx create-react-app my-app --template typescript
  2. cd my-app && npm install eslint-plugin-import
  3. define a baseUrl of "." in tsconfig.json (in "compilerOptions")
  4. create a 2 folders in "src/" (name them "a" and "b")
  5. create a file in each of them ("a/out.tsx" and "b/in.tsx")
  6. export a function from "a/out.tsx" (fn)
  7. import fn in "b/in.tsx" using an absolute path ("import {fn} from 'src/a/out';")
  8. check in "a/out.tsx" if eslint-plugin-import reports "fn" as not being used
  9. you can add a script in package.json for running the linter ("lint": "eslint . --ext .ts,.tsx")

eslint is configured in package.json like this:

{
  "eslintConfig": {
    "extends": [
      "react-app",
      "react-app/jest",
      "plugin:import/typescript"
    ]
    "settings": {
      "import/resolver": {
        "node": {
          "extensions": [
            ".ts",
            ".tsx"
          ],
          "paths": [
            "."
          ]
        }
      }
    },
    "rules": {
      "import/no-unused-modules": [
        "warn",
        {
          "missingExports": true,
          "unusedExports": true,
          "src": [
            "."
          ],
          "ignoreExports": [
            "src/**/*.d.ts"
          ]
        }
      ]
    }
  },
}

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions