-
Notifications
You must be signed in to change notification settings - Fork 349
Error unable to resolve path to module. eslint import/no-unresolved
but only in VSCode, not in ESLint CLI
#1994
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
Comments
Yes, I'm on mac. Nope, no additional things you need to do. I only have to upgrade this library and I see errors... |
I'm also facing the same issue. It seems to be reproducible when upgrading |
@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. |
Hi, I am also facing this issue! You don't need a repo, just install vue with create vue ( I have a fresh installation of Vue with vue-create. I am therefore using the flat-config. With these settings (w/o OxLint): For some reason, the default installation of Vue does not use the '@' alias. Once I change the imports to use the alias, I see the mentioned error. Vue comes with a default --EDIT-- Using the same command, I created a Vue project without TS. The CLI creates an I hope you can locate the issue… Because the issue is definitely in the vscode plugin for ESLint. When running ESLint in the CLI in both setups, I get the expected results. As in, no import errors. --EDIT-- |
@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. |
Ah, gotcha. I will get to it asap. I am occupied right now. I will make a report with all relevant local settings also. I will put those in a settingsfile in the repo.. |
Okay, I cannot believe this. I just arrived at my workplace only to realize that the screenshots I took earlier were fixed by elves. I cannot reproduce it anymore. |
I still do not have a repository reproducing this, but I managed to figure out how to fix it: In my package's
Then it works. My package is located in So it looks like the |
And another update: it worked for a few minutes, I continued to try to figure out a working config without this hardcoded path, and now the Could it be a different behaviour depending on the current active file when the When hardcoding this path to the full absolute path of the |
Yo @renchap, I have had the same problems after the overnight elves fixed my vscode, I returned to work over the weekend, and guess what, red scribbles everywhere.... Then, after some vigorous googling, I found this baby: https://www.npmjs.com/package/eslint-import-resolver-typescript Important notice: I am using This is my entire config, take out of it what you need, but pay attention to the // import plugin
flatConfigs.recommended,
flatConfigs.typescript,
{
rules: {
"import-x/consistent-type-specifier-style": ["error", "prefer-top-level"],
"import-x/first": "warn",
"import-x/newline-after-import": ["error", { count: 1 }],
"import-x/no-absolute-path": "error",
"import-x/no-relative-packages": "error",
"import-x/order": "off",
"sort-imports": "off",
"sort-keys": "off",
},
settings: {
"import-x/resolver-next": [
createTypeScriptImportResolver({
project: "./tsconfig.app.json",
}),
],
},
}, |
EDIT: Damn, i tricked myself :( |
I encountered this and was able to fix it by uninstalling the VSCode eslint plugin (both on remote and local, I am using WSL), restarting vscode, and reinstalling the plugin |
People never get tired of switching it off and on again :) Thx @lucaslcode. Unfortunately it doesn't really fix the problem on my machine/in my situation. {
"compilerOptions": {
"paths": {
"@repo/package-a/*": ["./*"]
}
}
} to enable absolute-ish imports like import SomeComponent from '@repo/package-a/src/components/SomeComponent in this package. To be able to do the same import in another package {
"compilerOptions": {
"paths": {
"@repo/package-a/*": ["../../packages/package-a/*"],
}
}
} Everything works outside of VS Code. ESLint, TS check. I just noticed something odd: ESLint in VS Code works for aliases defined in
This is odd. |
Hi @dbaeumer, can you have a look at https://github.com/iwan-uschka/vscode-eslint-issue-1994/tree/feature/with-flaky-error please? I added a README how to reproduce the odd behavior. I have to say that i wasn't able to create a monorepo from scratch reproducing this error. I ended up forking my project, removing everything unnecessary and adding some more code for testing purposes. Admitting that i am not sure if this is really/only a bug in some plugin or a misconfiguration of ESLint and/or TS in this repo. My setup: |
@renchap in general ESLint is very sensitive to the working directory. So if you have a mono repository you need to let the extension know the working directory that should be used when validating files. This is best done using the If you specify this then relative pathes in the config files should work as expected. |
I have this config: "eslint.workingDirectories": [
{ "pattern": "./packages/*/" },
], 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. |
Thank you @renchap!! After referencing TS config in ESLint config like import path from 'node:path';
import { fileURLToPath } from 'node:url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const tsConfigEsLintPath = path.resolve(__dirname, 'tsconfig.eslint.json');
const config = [
...
{
settings: {
'import/resolver': {
typescript: {
project: tsConfigEsLintPath,
},
},
},
},
];
export default config; (iwan-uschka/vscode-eslint-issue-1994@36405e5) 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 "eslint.workingDirectories": [{ "pattern": "./{apps,packages}/*/" }] and "eslint.workingDirectories": ["./apps/storybook-ui", "./packages/ui", "./packages/ui2"] a try without any luck. |
Seems same of import-js/eslint-import-resolver-typescript#447 (comment) Maybe |
@iwan-uschka I tried your original repository and even without any tweaking I was not able to reproduce this. |
@renchap do you have repository I can clone that demos what you are seeing. I would like to understand why relative paths don't work for you. |
@dbaeumer Did you check import-js/eslint-import-resolver-typescript#447 (comment)? I think this issue could happen when installing VSCode as arm64 arch, but installing Anyway, maybe a new target |
@JounQin thanks. This comment #1994 (comment) is definitely related to your link. @thewilkybarkid |
Thanks @dbaeumer for looking into it! Curious about #1994 (comment). I am running macOS on an Apple M1 (Silicon, arm64). |
@iwan-uschka Can you help to confirm:
|
@JounQin, here we go:
|
@iwan-uschka Thanks. |
Missing bits:
|
OK, then that's really a new issue compared with import-js/eslint-import-resolver-typescript#447 (comment)... I have no idea. |
This avoids an issue in the vscode eslint plugin causing the files to not be resolved properly (randomly): microsoft/vscode-eslint#1994 If you specify the absolute path to the `tsconfig.json`, then everything works
Uh oh!
There was an error while loading. Please reload this page.
I upgraded the package eslint-import-resolver-typescript from
3.7.0
to4.2.1
and VSCode ESLint shows errorsunable to resolve path to module. eslint import/no-unresolved
on my imports.I created an issue on the
eslint-import-resolver-typescript
repo (import-js/eslint-import-resolver-typescript#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
The text was updated successfully, but these errors were encountered: