2.0.0 Doesn't work with lodash
le0nik opened this issue ยท 9 comments
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"
}
Then what's your actual codes? I'm using lodash without any problem.
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.
@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
.
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.
@sakulstra I think it is just as expected, you can see https://unpkg.com/browse/dataloader@1.4.0/index.d.ts.
And also, I personally disable
import/default
andimport/named
for.tsx?
files which should have been handled by typescript-eslint.
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?
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.
@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
.
@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'
.