typescript-eslint-language-service icon indicating copy to clipboard operation
typescript-eslint-language-service copied to clipboard

eslint-plugin-import fails to resolve project aliases/paths with yarn workspaces inside the service while using LSP

Open rassie opened this issue 2 years ago • 1 comments

This one is a rabbit hole. The problem is similar to https://github.com/import-js/eslint-plugin-import/issues/2301, but is more localized to typescript-eslint-language-service.

I've got a monorepo project set up with yarn workspaces. Inside one of the workspaces is a Typescript project with ESLint (based on Vite). This project is configured to use typescript-eslint-language-service while ESLint is configured to use eslint-import-plugin. We are using a path/alias configuration to avoid relative imports, so that src/* imports are mapped to the src directory. This configuration is added to both tsconfig.json (compilerOptions.path) and also to vite.config.ts (which is probably irrelevant to this issue, since ESLint doesn't normally read this setting).

My editor configuration is using typescript-language-server, which runs tsserver which in turn runs typescript-eslint-language-service.

Now the actual problem: standalone tsc has no problem building the project, standalone ESLint does not find any problems in the codebase either, so we can presume it's clean from both TypeScript and ESLint point of view. However, eslint-import-plugin running inside typescript-eslint-language-service inside tsserver started by typescript-language-server started from my editor cannot resolve src/MyModule, while it can resolve every third-party module from package.json.

I can resolve this problem in the editor by setting a eslint-import-resolver-typescript project configuration:

    settings: {
        'import/resolver': {
            typescript: {
                project: ['packages/core/tsconfig.json']
            }
        }
    }

but this breaks ESLint's import resolution from the console.

So I've got a lot of moving parts and basically no idea anymore what I could do differently. I'm not sure this is a bug, possibly a configuration error. Any idea what could be wrong?

rassie avatar Dec 21 '21 09:12 rassie

@rassie have you tried setting your monorepos root .tsconfig to the projects array? project: ['./tsconfig.json', 'packages/core/tsconfig.json']

nik-webdevelop avatar Apr 07 '22 13:04 nik-webdevelop