Skip to content

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

@rassie

Description

@rassie

This one is a rabbit hole. The problem is similar to import-js/eslint-plugin-import#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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions