-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
import/no-unresolved errors for .d.ts files since 2.25 #2267
Comments
This was introduced by 4d15e26 (#2220). Cc @jabiko. Minimal reproduction: // foo.ts
import { bar } from "./bar";
console.log(bar); // bar.d.ts
export const bar: string; // .eslintrc.json
{
"plugins": ["@typescript-eslint", "import"],
"parser": "@typescript-eslint/parser",
"extends": "plugin:import/typescript",
"rules": {
"import/no-unresolved": "error"
}
} $ npm i -D @typescript-eslint/[email protected] @typescript-eslint/[email protected] [email protected] [email protected] [email protected]
$ npx eslint foo.ts
/home/anders/zulip/test/eslint-import-bug/foo.ts
2:21 error Unable to resolve path to module './bar' import/no-unresolved
✖ 1 problem (1 error, 0 warnings) |
@andersk that looks like a bug fix to me - if there’s no actual bar file there, then what are you importing? d.ts files are for providing types, not for pretending there’s a real runtime value there. In other words, there needs to also be a bar.js file there next to the bar.d.ts file. |
In a pure typescript environment it's normal to use .d.ts files that just provide types or interfaces but no functions. E.g. if you want to share types between multiple ts files. |
Even if this is a bug fix, it's still a breaking change in behaviour and shouldn't be present in a patch release. |
Adding
to my eslint config helped a lot, because then eslint was able to autofix this. But still: This breaking changes in patch releases are bad :/ |
@mrdrogdrog it's not normal to have a .d.ts file and no corresponding .js file to be imported. Yes, breaking changes in patch releases are bad, but every single bug fix is a breaking change if someone's relying on the bug. I see what you mean tho - in this case, you're importing a type, but you weren't using the preferred I think the issue is that you're not using the TS resolver (but neither is https://github.com/import-js/eslint-plugin-import/blob/main/config/typescript.js#L18-L22). If you add the TS resolver - above |
Oh no! I became the person in this xkcd 🙈 |
I read the typescript and eslint docs again and changed my code to use "import type" and the "consistent-type-import" rule I mentioned above. Maybe you should improve the error message somehow? "unable to resolve path to module" is a bit confusing if you're sitting there and think "but the file exists o.ö" |
I get also problems with I'm using the config If I have a file
That is wrong in my opinion. e.g. when I want to describe the expected messages of a communication I add them to an own file. So it could be, that the most are not doing this but I want to be able to do it like I think it is good. Can we provide an But for now I have to disable all the rules :-( edit:
the |
I've the same issue as @Ulrikop . I downgraded to |
OK, to sum up: When using the typescript resolver, and importing a type, or an enum, from a When not using the typescript resolver, and using typescript, your config is unsupported. cc @jablko, it'd be great to roll forward with a fix so we don't have to revert #2220. |
@mrdrogdrog does #2270 seem like it solves your issue? |
the changes of @jablko does not fix all problems. Given:
Then I get the error
a |
@Ulrikop are you checking with the latest master? I haven't released those fixes yet. |
Yes, I copied the changes of the PR #2270 into my node_modules directory. The following previously mentioned issue is resolved with the change:
But since the fix on the PR only changes that an |
thanks for confirming. cc @jablko :-) |
Great point, thanks for the feedback!
By importing from There's no way for eslint-plugin-import to know whether it will be elided or not, however. There should be a way to mark an import compile-time only, and Until there's such a way, I think the best would be to mark your import compile-time only in the eyes of eslint-plugin-import at least: Alternatively you can restore the old behavior yourself by customizing the ... |
For me this topic is done. I changed our code to use I don't see the behavior of eslint as a bug anymore. Thank you for your help |
@Ulrikop Thinking more about this, and TypeScript maintainers' amenity to value usage of type-only const enums: microsoft/TypeScript#42991 (comment) If isolatedModules matters to you, could you rename |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Sorry for my late answer. due to an emergency in my family, I don't have time to test anything at the moment (e.g. adding |
Have you tried |
It did work when I use
this is my code https://github.com/ZJS248/test/blob/master/src/main.ts |
@ZJS248 Thanks for the code, I haven't tried linting it myself yet ... Can you elaborate on the false positives/it causes errors that you're seeing? My belief is that the import/no-unresolved rule currently skips |
In future ESLint 8, this plugin must be enabled. We are currently blocked from updating due to a bug in eslint-plugin-import @link import-js/eslint-plugin-import#2267
In future ESLint 8, this plugin must be enabled. We are currently blocked from updating due to a bug in eslint-plugin-import @link import-js/eslint-plugin-import#2267
Environment
Node: 16.11.1
ESLint: 7.32.0
Operating System: Linux
What happened?
We tried to update eslint-plugin-import in https://github.com/hedgedoc/react-client from 2.24.2 to 2.25.2 but eslint fails now. It can't resolve paths to
.d.ts
files anymore.What did I expect?
No breaking changes in behaviour since it isn't a major release.
Additional Information
Feel free to take a look at our CI log.
https://github.com/hedgedoc/react-client/runs/3915016791?check_suite_focus=true
Thanks for your help
The text was updated successfully, but these errors were encountered: