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

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

Open
rassie opened this issue Dec 21, 2021 · 1 comment

Comments

@rassie
Copy link

rassie commented Dec 21, 2021

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?

@nik-webdevelop
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants