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

2.0.0 Doesn't work with lodash #31

Closed
le0nik opened this issue Oct 8, 2019 · 9 comments
Closed

2.0.0 Doesn't work with lodash #31

le0nik opened this issue Oct 8, 2019 · 9 comments

Comments

@le0nik
Copy link

le0nik commented Oct 8, 2019

It always throws errors like this(no errors in previous version):

9:10  error  throttle not found in 'lodash'  import/named

Node version: 12.11.1

Relevant dependencies:

{
    "@typescript-eslint/parser": "2.3.3",
    "@types/lodash": "4.14.142",
    "eslint": "6.5.1",
    "eslint-import-resolver-typescript": "2.0.0",
    "eslint-plugin-import": "2.18.2",
    "lodash": "4.17.15",
    "typescript": "3.6.3"
}
@JounQin
Copy link
Collaborator

JounQin commented Oct 8, 2019

Then what's your actual codes? I'm using lodash without any problem.

@le0nik
Copy link
Author

le0nik commented Oct 8, 2019

Here's a minimal repro: https://github.com/le0nik/resolver-typescript-repro

If you remove the 'import/extensions': ['.ts', '.tsx', '.d.ts', '.js', '.jsx'], line from .eslintrc.js you get no more errors, but that's just because import plugin doesn't even see the typescript files. You can easily check this by changing throttle import to something non-existent - there still won't be any errors.


As an aside: I think that requirement to add baseUrl to compilerOptions in tsconfig.json should be specified in the README, it's not quite obvious and there is no error if it's not present.

@JounQin
Copy link
Collaborator

JounQin commented Oct 8, 2019

@le0nik OK, I see. Now @types/lodash/index.d.ts takes higher priority than lodash/index.js, but eslint-plugin-import didn't understand ts namespace with esInterop correctly.

@benmosher Please point me if I'm incorrect.

And also, I personally disable import/default and import/named for .ts which should have been handled by typescript-eslint.

@sakulstra
Copy link

With the 2.0.0 update we're now getting an error from:

import Dataloader from "dataloader";
error  No default export found in module  import/default

not sure i this is related though.

@JounQin
Copy link
Collaborator

JounQin commented Oct 9, 2019

@sakulstra I think it is just as expected, you can see https://unpkg.com/browse/[email protected]/index.d.ts.

And also, I personally disable import/default and import/named for .tsx? files which should have been handled by typescript-eslint.

@JounQin
Copy link
Collaborator

JounQin commented Oct 9, 2019

I'm going to close this issue, because it is just working as expected, see my comments above, and I do think it relates to eslint-plugin-import itself.

@benmosher Any advice for this?

@mickdekkers
Copy link

It looks like I may have found a solution. Try adding this to your eslint config:

settings:
  import/resolver:
    node:
      extensions:
        - .ts
        - .tsx
        - .js
        - .jsx

This fixes the issue for me, making import/named and import/default work as expected.

@JounQin
Copy link
Collaborator

JounQin commented Feb 17, 2020

@mickdekkers I don't think it's a proper solution, if eslint-import-resolver-node takes higher priority than eslint-import-resolver-typescript, it may not resolve @types/ packages at all. Because node will resolve node_modules/lodash first instead of node_modules/@types/lodash.

@tomyam1
Copy link

tomyam1 commented Feb 25, 2020

@mickdekkers
I don't think it's a solution at all.
You're essentially using the node resolver instead of the typescript resolver (unless the node resolver fails)

And lodash is mapped to node_modules\lodash\lodash.js.

As a result, it seems that all imports are passes, even non existing ones, e.g. import { xxx} from 'lodash'.

mcmire added a commit to MetaMask/metamask-extension that referenced this issue Feb 2, 2022
When ESLint is configured to prefer TypeScript modules over JavaScript
(even in JavaScript files), attempting to import a named export from
`lodash` fails the `import/named` rule with something like:

    capitalize not found in 'lodash'

This seems to happen because `index.d.ts` links to other `.d.ts` files
via `/// <reference ...>`, and either `eslint-plugin-import` or
`eslint-import-resolver-typescript` does not know to follow those links.
(I say "either" because I haven't quite been able to figure out where the
exact issue is. The current maintainer of
`eslint-import-resolver-typescript` hasn't provided any useful
information; [here][1] is the closest issue on GitHub I've been able to
find that could explain something.) However, `lodash-es` does not
exhibit this issue, as its `index.d.ts` just imports types for
individual functions from other files instead of using `/// <reference
...>`.

[1]: import-js/eslint-import-resolver-typescript#31
@JounQin JounQin unpinned this issue Aug 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

5 participants