import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.
MIT License
5.56k stars 1.57k forks source link

eslint-import-resolver-node: Regression with import/default #2182

Closed srittau closed 3 years ago

srittau commented 3 years ago

When upgrading eslint-import-resolver-node from 0.3.4 to 0.3.5, the following line starts to trigger the import/default warning:

import Redux from "redux";

The installed redux version is 4.1.1. Please let me know if you need any more information.

danez commented 3 years ago

Similar issue here: https://github.com/reactjs/react-tabs/pull/412, worked before.

kachkaev commented 3 years ago

Looks like a general issue with eslint-import-resolver-node 0.3.5, which affects other rules too. I shared a temp workaround here: https://github.com/import-js/eslint-plugin-import/issues/2186#issuecomment-895963790.

ljharb commented 3 years ago

@srittau can you provide the full warning being triggered?

Redux 4.1.1's "module" field points at https://unpkg.com/browse/redux@4.1.1/es/redux.js, which does not in fact have a default export, so this seems correct to me.

srittau commented 3 years ago

Sure, this is from one of my projects:

srittau@robinson:~/test$ ./node_modules/.bin/eslint js-src --ext .js,.jsx,.ts,.tsx

/home/srittau/test/js-src/apps/main-index/messages.ts
  1:8  error  No default export found in imported module "redux"  import/default

/home/srittau/test/js-src/apps/team/index.tsx
  5:8  error  No default export found in imported module "redux"  import/default

/home/srittau/test/js-src/apps/time-tracker/index.tsx
  5:8  error  No default export found in imported module "redux"  import/default

✖ 3 problems (3 errors, 0 warnings)

Changing the affected lines to import * as Redux from 'redux' fixes/works around this problem and you are of course correct about the implementation not having a default export. It's possible that the old import worked at runtime, only because I'm bundling redux and using it as an external dependency. Still interesting that it used to work.

ljharb commented 3 years ago

The reason it used to work is because eslint-import-resolver-node used to only look at "main" and "jsnext:main" - but redux at some point added "module" (which eslint-import-resolver-node only started using in v0.3.5) and then dropped jsnext:main (which it shouldn't have done).

In other words, I think this is a correct warning, and the bug was that it was passing the linter before. Thus, I'm going to close the issue.

My personal suggestion would be to import { specific, things } from 'redux' rather than using import * or trying to use an object as a "bag o stuff" :-)

ljharb commented 3 years ago

@kachkaev @danez if you are having an issue with a package that does have a "module" field pointing to a file with a default export, then please file a new issue and I'll fix it ASAP!