Skip to content

fix: resolve tsconfig extends packages from ancestor node_modules - #631

Merged
alexander-akait merged 4 commits into
mainfrom
claude/webpack-issue-21457-nlrg1j
Jul 20, 2026
Merged

alexander-akait merged 4 commits into
mainfrom
claude/webpack-issue-21457-nlrg1j

Conversation

@alexander-akait

Copy link
Copy Markdown
Member

Summary

A tsconfig extends package specifier was only looked up in the config file's own node_modules, so a shared config hoisted to a parent workspace's node_modules failed to resolve. _loadTsconfigFromExtends now walks up ancestor directories like Node.js/TypeScript module resolution. Fixes webpack/webpack#21457.

What kind of change does this PR introduce?

fix

Did you add tests for your changes?

Yes — a regression test and extends-npm-workspace fixture in test/tsconfig-paths.test.js covering a scoped package extends hoisted to a parent node_modules.

Does this PR introduce a breaking change?

No.

If relevant, what needs to be documented once your changes are merged or what have you already documented?

n/a

Use of AI

Claude Code was used to locate the faulty node_modules lookup, implement the ancestor-directory walk, and write the regression test; all changes were reviewed by a human.


Generated by Claude Code

A tsconfig "extends" package specifier was only looked up in the
config file's own node_modules directory, so a shared config hoisted
to a parent workspace's node_modules failed to resolve. Walk up the
ancestor directories like Node.js/TypeScript module resolution.

Closes #21457
Copilot AI review requested due to automatic review settings July 20, 2026 01:04

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The Node 12-16 leg installs jest ad-hoc without a lockfile, so it
floats transitive deps to their latest versions. A newly published
js-yaml@4.3.0 requirement then failed with ETARGET because
--prefer-offline resolved against a stale npm cache that predated it.
Revalidating against the registry fixes the install.
Copilot AI review requested due to automatic review settings July 20, 2026 01:54
@changeset-bot

changeset-bot Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 9c6a8c5

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
enhanced-resolve Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codecov

codecov Bot commented Jul 20, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.12%. Comparing base (82026bf) to head (9c6a8c5).

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #631   +/-   ##
=======================================
  Coverage   98.11%   98.12%           
=======================================
  Files          49       49           
  Lines        9867     9902   +35     
=======================================
+ Hits         9681     9716   +35     
  Misses        186      186           
Flag Coverage Δ
integration 98.12% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ 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.

Adds a case where extends is a non-existent dot-prefixed value that is
not a package specifier, exercising the direct-load fallback branch
(patch coverage).
Copilot AI review requested due to automatic review settings July 20, 2026 01:59

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The async form timed out under jest (legacy Node + deno runners) even
though it resolves instantly on node:test. Driving it through
resolveSync + assert.throws (like the other sync tsconfig cases) is
deterministic and covers the same fallback branch.
Copilot AI review requested due to automatic review settings July 20, 2026 02:05

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@codspeed

codspeed Bot commented Jul 20, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 13.27%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 2 regressed benchmarks
✅ 140 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ Simulation concurrent-batch: Promise.all of 15 resolves (warm) 1.4 ms 1.6 ms -13.94%
❌ Simulation realistic-midsize: mixed batch (cold cache) 6.9 ms 7.8 ms -12.6%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing claude/webpack-issue-21457-nlrg1j (9c6a8c5) with main (82026bf)

Open in CodSpeed

@alexander-akait
alexander-akait merged commit d50e202 into main Jul 20, 2026
37 of 38 checks passed
@alexander-akait
alexander-akait deleted the claude/webpack-issue-21457-nlrg1j branch July 20, 2026 05:28
alexander-akait pushed a commit that referenced this pull request Jul 20, 2026
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## enhanced-resolve@5.24.3

### Patch Changes

- Resolve tsconfig `extends` package specifiers from ancestor
node_modules directories (workspace hoisting). (by
[@alexander-akait](https://github.com/alexander-akait) in
[#631](#631))

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
alexander-akait pushed a commit that referenced this pull request Nov 12, 2026
<!-- Thanks for submitting a pull request! Please provide enough
information so that others can review your pull request. -->

**Summary**

<!-- Explain the **motivation** for making this change. What existing
problem does the pull request solve? -->
<!-- Try to link to an open issue for more information. -->
<!-- Any other information related to changes. -->

Fixes #706.

`TsconfigPathsPlugin` builds `extends` paths by hand. It appends `.json`
to any value without `.json` in it, and maps package names to
`node_modules` paths itself. tsc treats `./`, `../` and absolute values
as files (`.json` optional) and resolves everything else like a
`require`. So four forms that tsc accepts fail the whole tsconfig,
including the project's own `paths`.

This keeps the file branch and resolves everything else with a child
resolver set up like tsc's config lookup: `exports` with the
`require`/`types`/`node` conditions, the `tsconfig` field, then
`tsconfig.json`. That replaces the package special cases added in #483,
#575 and #631. Like tsc, backslashes are normalized first. When the
lookup fails, a bare file name such as `"tsconfig.base.json"` still
loads from the config's directory, as it always has here, though tsc
rejects it.

Resolving `@/foo` with the #706 repro, where tsc gives `src/foo.ts` for
all four:

| `extends` | Before | After |
| ---------------------------------- |
------------------------------------------ | ------------ |
| `"cfgpkg/strict"` via `exports` | `ENOENT …
node_modules/cfgpkg/strict.json` | `src/foo.ts` |
| `"cfgpkg"` with a `tsconfig` field | `ENOENT …
node_modules/cfgpkg/tsconfig.json` | `src/foo.ts` |
| `"./configs/base.tsconfig"` | `ENOENT … configs/base.tsconfig.json` |
`src/foo.ts` |
| `".."` | `ENOENT … dotdot/pkg/...json` | `src/foo.ts` |

<!-- In addition to that please answer these questions: -->

**What kind of change does this PR introduce?**

<!-- E.g. a fix, feat, refactor, perf, test, chore, ci, build, style,
revert, docs or describe it if you did not find a suitable kind of
change. -->

fix

**Did you add tests for your changes?**

<!-- Please note: in most cases, if you change the code, we will not
merge your changes unless you add tests. -->

Yes: five cases in `test/tsconfig-paths.test.js`, with fixtures in
`test/fixtures/tsconfig-paths/extends-resolution/`. The four #706 forms
fail on `main`. The `..` case also checks that a sibling `<dir>.json`
doesn't win. The bare file name case passes on `main` and guards the
kept fallback.

**Does this PR introduce a breaking change?**

<!-- If this PR introduces a breaking change, please describe the impact
and a migration path for existing applications. -->

No.

**If relevant, what needs to be documented once your changes are merged
or what have you already documented?**

<!-- List all the information that needs to be added to the
documentation after merge that has already been documented in this PR.
-->

n/a

**Use of AI**

<!-- If you have used AI, please state so here. Explain how you used it.
Make sure to read our AI policy
(https://github.com/webpack/governance/blob/main/AI_POLICY.md) or your
Pull Request may be closed due to irresponsible use of AI. -->

Yes. I used Claude Code to write the change and the tests. I reviewed
every line, checked each case against tsc's `getExtendsConfigPath`, and
ran `npm run lint` and the full test suite locally.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->

<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* TypeScript configuration inheritance now follows TypeScript-style path
resolution, including package exports, package configuration fields,
extensionless config files, and parent-directory references.
* Unsupported bare filenames are no longer treated as valid
configuration paths.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

tsconfig extends resolution broken

2 participants