vscode-eslint: Error `unable to resolve path to module. eslint import/no-unresolved` but only in VSCode, not in ESLint CLI
I upgraded the package eslint-import-resolver-typescript from 3.7.0 to 4.2.1 and VSCode ESLint shows errors unable to resolve path to module. eslint import/no-unresolved on my imports.
I created an issue on the eslint-import-resolver-typescript repo (https://github.com/import-js/eslint-import-resolver-typescript/issues/396) but as the error is related to VSCode and not ESLint CLI, the main contributor suggested me to create an issue on your repository.
The package uses a napi module: rspack-resolver under the hood.
You can easily reproduct the issue by cloning my project : docker-express-postgres-boilerplate and upgrading the library eslint-import-resolver-typescript
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 4
- Comments: 48 (14 by maintainers)
I will close the issue since the fix will be provided by @JounQin in the ESLint plugin. Thank you @JounQin
@dbaeumer Did you check https://github.com/import-js/eslint-import-resolver-typescript/issues/447#issuecomment-2857344827?
I think this issue could happen when installing VSCode as arm64 arch, but installing
unrs-resolverin terminal inx86_64although I don’t know what’s happening, maybe the system Node binary is installed via Rosetta 2? cc @valleywoodAnyway, maybe a new target
universal-apple-darwinfornapi-rswould help.@JounQin you can change the working directory using
process.cwd('new path'). The cache I had in mind was https://github.com/un-ts/eslint-plugin-import-x/blob/master/src/utils/module-cache.ts but please be aware that I only looked through the code today for ~20 minutes.@JounQin I investigate @auirarrazaval repro and here is what is happening:
process.cwd()ispackages\eslintorapps\app-1depending on which file is validatedprocess.cwdcallCould it be that the caching is not expected the
process.cwdto change? That would explain the different results depending on which files opens first.OK, then that’s really a new issue compared with https://github.com/import-js/eslint-import-resolver-typescript/issues/447#issuecomment-2857344827… I have no idea.
Thank you @renchap!! After referencing TS config in ESLint config like
(https://github.com/iwan-uschka/vscode-eslint-issue-1994/commit/36405e54a75cdfae0974b8758b8dc99f60dec880)
i couldn’t reproduce the issue 🎉 So cool. Hopefully the problem is now fixed and not just less flaky.
@dbaeumer Before in my demo monorepo i gave
and
a try without any luck.
I have this config:
I also tried to list the packages directly, but it still sometimes stop working randomly
Right now the only way I found to not have those random breakages is to hardcode the path in the eslint import config:
If I omit it, or use a relative directory, after some point eslint ran by the vscode plugin stops resolving the paths proprely.
@Serhansolo I would really prefer a GitHub repository I can clone. This ensures that I do use the same exact content and settings as you do. This repository should also contain you local VS Code settings if you changed any.
@renchap do you have a GitHub repository I can clone that demos this. May be I can reproduce it there. Without being able to reproduce the error it is very hard to say what is the root cause of this.
I’m also facing the same issue. It seems to be reproducible when upgrading
eslint-import-resolver-typescriptto version 3.9.0 or later. For reference, I’m also using a macOS.