import-js / import-js/eslint-plugin-import

`import/named` false positive when re-exporting internal dependencies with pnpm

Open
#2,903 7 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
JavaScript
Stars
5.9k
Forks
1.5k
PR merge metrics
No merged PRs in 30d

Description

When using PNPM, re-exporting internal dependencies triggers import/named, while TypeScript resolves everything correctly:
image

Steps to reproduce

eslint: "8.52.0"
eslint-plugin-import: "2.28.1"
node: "18.12.1"
pnpm: "8.9.2"

I wasn't able to build a minimal repro in proper timeframe, but the general idea is that given

// package-outer/index.js
export * from 'package-inner'

// package-inner/index.js
export const a = 42

When installed via pnpm, results in roughly the following structure:

node_modules
├ .pnpm
│ ├ package-outer@1.0.0
│ │ └ node_modules
│ │   ├ package-inner -> .pnpm/package-inner@1.0.0/node_modules/package-inner
│ │   └ package-outer
│ │     └ ... source code ... 
│ └ package-inner@1.0.0
│   └ node_modules
│     └ package-inner
│       └ ... source code ...
└ package-outer -> .pnpm/package-outer@1.0.0/node_modules/package-outer

Where eslint-plugin-import likely fails to resolve package-inner when introspecting package-outer, which results in import/named false positives.

Expected behaviour

Exports are correctly resolved from re-exported internal packages, no error is thrown

Actual behaviour

import/named is thrown

Possible workaround

The issue can be worked around by installing package-outer at the top level.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the import/named rule and the package-outer/index.js and package-inner/index.js re-export example. Reproduce the pnpm .pnpm node_modules layout described in the issue, then trace how package-inner is resolved while introspecting package-outer. Done means the re-exported a export is resolved without an import/named error.

Written by the indexing model from the issue text.

Assessment

Tech stack
eslint, javascript
Domain
tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.