Skip to content
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

Not resolving tsconfig paths #2652

Closed
SimonCockx opened this issue Jan 7, 2023 · 11 comments
Closed

Not resolving tsconfig paths #2652

SimonCockx opened this issue Jan 7, 2023 · 11 comments

Comments

@SimonCockx
Copy link

SimonCockx commented Jan 7, 2023

I have two projects, project-a and project-b, one importing the other via a paths synonym defined in tsconfig.base.json. Although the TypeScript compiler knows how to resolve the import, this plugin is complaining that it cannot resolve the path.

I've read the documentation of both this plugin and the TypeScript resolver plugin, and I think I configured everything right, but with no luck. Is there something wrong with my setup?

Minimal repro:

Snippets:

tsconfig.base.ts

"compilerOptions": {
  "paths": {
    "@importbug/b": ["project-b/src/index.ts"]
  },
  ...
}

project-a/.eslintrc.json

{
  "plugins": [
    "@typescript-eslint",
    "import"
  ],
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "project": ["project-a/tsconfig.json"],
    "sourceType": "module"
  },
  "settings": {
    "import/resolver": {
      "typescript": {
        "alwaysTryTypes": true,
        "project": "tsconfig.json",
        "extensions": [".ts"]
      }
    },
    "import/parsers": {
      "@typescript-eslint/parser": [
        ".ts", ".tsx"
      ]
    }
  },
  "extends": [
    "plugin:import/typescript", "plugin:import/recommended"
  ]
}

project-a/src/index.ts

import { b } from "@importbug/b";
                   ^^^^^^^^^^^
b;
@ljharb
Copy link
Member

ljharb commented Jul 26, 2023

Try extending plugin:import/typescript?

@SimonCockx
Copy link
Author

@SimonCockx
Copy link
Author

Interestingly, I just found out that running eslint succeeds if I cd into project-a and change

"parserOptions": {
    "project": ["project-a/tsconfig.json"],
    "sourceType": "module"
  },

into

"parserOptions": {
    "project": ["tsconfig.json"],
    "sourceType": "module"
  },

Could this be a bug with the way that eslint handles configuration that is not in the project root?

@ljharb
Copy link
Member

ljharb commented Aug 4, 2023

We're using tsconfig-paths v3, which doesn't support "extends", i believe - that might be relevant.

@SimonCockx
Copy link
Author

@ljharb Not sure how that's relevant for the issue I've described. I don't use tsconfig-paths, and I think eslint acts directly on the source files, so I assume it doesn't care about the problem that tsconfig-paths sets out to solve.

@ljharb
Copy link
Member

ljharb commented Aug 5, 2023

@SimonCockx eslint-plugin-import uses tsconfig-paths in order to resolve typescript settings.

@zeorin

This comment was marked as resolved.

@JounQin

This comment was marked as resolved.

@JounQin JounQin closed this as not planned Won't fix, can't repro, duplicate, stale Nov 9, 2023
@ljharb

This comment was marked as resolved.

@ljharb ljharb reopened this Nov 9, 2023
@JounQin
Copy link
Collaborator

JounQin commented Nov 9, 2023

Hmm... But it seems we are not going to upgrade tsconfig-paths at all. #2447 🤣

@ljharb
Copy link
Member

ljharb commented Nov 9, 2023

That remains open, and if an issue (such as this one) has no solution it should remain open indefinitely.

@ljharb ljharb closed this as completed in 48fec35 Dec 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants