Skip to content

[Deps] let user know eslint-import-resolver-node needs to be in root of node_modules (important when using install-strategy=linked) - #3266

Open
nikolawork wants to merge 2 commits into
import-js:mainfrom
nikolawork:eslint-import-resolver-node-in-peer-depencies
Open

nikolawork wants to merge 2 commits into
import-js:mainfrom
nikolawork:eslint-import-resolver-node-in-peer-depencies

Conversation

@nikolawork

@nikolawork nikolawork commented Jul 13, 2026

Copy link
Copy Markdown

Using install-strategy=linked only puts the packages from dependencies and devDependencies in the root of node_modules. This means that eslint-import-resolver-node is not in the root of node_modules which leads to the following error:

Resolve error: unable to load resolver "node"

This is fixed by adding eslint-import-resolver-node to your package.json. We signal this to the user by adding eslint-import-resolver-node to peerDependencies.

install-strategy=linked is stable since npm@11.18.0: https://docs.npmjs.com/cli/v11/using-npm/config#install-strategy

npm even recommends using it when developing. From the above link:

We recommend that package authors use --install-strategy=linked during development to catch undeclared ("phantom") dependencies before publishing: the isolated layout only exposes a package's declared dependencies, so an import of a package that was never added to package.json can fail instead of resolving by accident and shipping broken. See Catching undeclared ("phantom") dependencies.

There is a closed (but unresolved) issue for this: #828

…t of node_modules (important when using `install-strategy=linked`)

Using `install-strategy=linked` only puts the packages from `dependencies` and `devDependencies` in the root of node_modules. This means that `eslint-import-resolver-node` is not in the root of node_modules which leads to the following error:

```
Resolve error: unable to load resolver "node"
```

This is fixed by adding `eslint-import-resolver-node` to your `package.json`. We signal this to the user by adding `eslint-import-resolver-node` to `peerDependencies`.

`install-strategy=linked` is stable since `npm@11.18.0`.
@nikolawork
nikolawork marked this pull request as ready for review July 13, 2026 08:04
@codecov

codecov Bot commented Jul 13, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.58%. Comparing base (bf2d2aa) to head (eb02bd8).
⚠️ Report is 13 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3266   +/-   ##
=======================================
  Coverage   79.58%   79.58%           
=======================================
  Files          98       98           
  Lines        4527     4527           
  Branches     1560     1560           
=======================================
  Hits         3603     3603           
  Misses        924      924           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@nikolawork

Copy link
Copy Markdown
Author

This fix can also be added to the fix in #2283 and then we can close this PR.

@manzoorwanijk

Copy link
Copy Markdown

I see the dependency is already being declared correctly.

"eslint-import-resolver-node": "^0.4.0",

@nikolawork

Copy link
Copy Markdown
Author

I see the dependency is already being declared correctly.

The problem is the way the dependency is being resolved here:

const resolver = tryRequire(`eslint-import-resolver-${name}`, sourceFile)
|| tryRequire(name, sourceFile)
|| tryRequire(path.resolve(getBaseDir(sourceFile), name));

The only way this works is if eslint-import-resolver-node is in the root of node_modules. Which it isn't when using install-strategy=linked if the dependency is not declared in the end user's package.json (which you should definitely know haha).

@manzoorwanijk

Copy link
Copy Markdown

The problem is the way the dependency is being resolved here:

Yes, that is what I was going to write. That require logic may need to be updated to ensure it works in isolated dependencies layout.

@ljharb

ljharb commented Jul 15, 2026

Copy link
Copy Markdown
Member

This is intentional, and is why the "linked" strategy (and yarn's PNP, and similar approaches) is fundamentally flawed.

Adding it to peer deps explicitly increases maintenance burden and could be a breaking change.

@manzoorwanijk

Copy link
Copy Markdown

I have created a dedicated bug report for it - #3268

Also created a PR to fix it - #3269

@manzoorwanijk

Copy link
Copy Markdown

But the CI is broken because of npm v12.

@ljharb

ljharb commented Jul 16, 2026

Copy link
Copy Markdown
Member

the npm 12 thing is fixed, if you rebase.

Comment thread package.json
"peerDependencies": {
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 || ^9 || ^10"
"eslint": "^2 || ^3 || ^4 || ^5 || ^6 || ^7.2.0 || ^8 || ^9 || ^10",
"eslint-import-resolver-node": "^0.4.0"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note that this is a breaking change, because it will fail if someone has a newer version installed at a higher level.

@manzoorwanijk

Copy link
Copy Markdown

the npm 12 thing is fixed, if you rebase.

Your commit seems to have used another failure - https://github.com/import-js/eslint-plugin-import/actions/runs/29535690274/job/87764990067

@nikolawork

Copy link
Copy Markdown
Author

I have created a dedicated bug report for it - #3268

Also created a PR to fix it - #3269

Thanks for the more thorough fix, @manzoorwanijk. If that PR is merged, we can close my PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants