Skip to content

fix: tsconfig extends supporting same extensions (inc .jsonc) for relative and package imports (bug #43121)#62092

Closed
domdomegg wants to merge 3 commits intomicrosoft:mainfrom
domdomegg:fix-43121
Closed

fix: tsconfig extends supporting same extensions (inc .jsonc) for relative and package imports (bug #43121)#62092
domdomegg wants to merge 3 commits intomicrosoft:mainfrom
domdomegg:fix-43121

Conversation

@domdomegg
Copy link
Copy Markdown

Fixes #43121

This PR adds support for .jsonc file extensions when resolving tsconfig extends paths through Node.js module resolution. Previously, TypeScript only supported .jsonc files for relative paths (e.g., "extends": "./config.jsonc") but failed when trying to resolve package-based extends (e.g., "extends": "pkg/config.jsonc").

Problem

When using "extends": "pkg/foo.jsonc" in a tsconfig.json, TypeScript would attempt to resolve node_modules/pkg/foo.jsonc.json and fail, even though the same .jsonc file could be successfully loaded using relative paths like "extends": "./foo.jsonc".

This inconsistency forced developers to either:

  • Use .json extensions and deal with linter warnings about comments
  • Rely on special-case handling by dev tools for tsconfig*.json files
  • Avoid package-based config sharing with .jsonc files

Changes

Core Resolution Changes

  • src/compiler/moduleNameResolver.ts:

    • Renamed nodeNextJsonConfigResolver to nodeNextTsconfigResolver
    • Changed config lookup to use Extensions.Any instead of Extensions.Json. I was thinking about adding a Jsonc Extensions value, but decided against this so the behaviour of relative tsconfig and package tsconfig imports would be the same (any extensions are valid for relative imports)
  • src/compiler/commandLineParser.ts:

    • Updated import and function call to use the renamed resolver

Testing

Added test cases before starting, to ensure test went from failing to passing:

  • tests/cases/compiler/tsconfigExtendsJsoncPackage.ts: Tests package-based .jsonc extends
  • tests/cases/compiler/tsconfigExtendsJsoncRelative.ts: Ensures relative .jsonc extends still work (regression test)

Both test cases verify that:

  • The .jsonc config files are properly resolved and loaded
  • Compiler options from the extended config are applied correctly
  • Source maps are generated as expected when inlineSourceMap: true is set

Backward Compatibility

This change is fully backward compatible:

  • Existing .json config files continue to work exactly as before
  • Relative .jsonc paths that already worked remain unchanged

This aligns tsconfig relative and package import behaviour: to enable all extensions (e.g. .jsonc, .tsconfig, ...). This fixes bug microsoft#43121
@github-project-automation github-project-automation bot moved this to Not started in PR Backlog Jul 19, 2025
@typescript-bot typescript-bot added the For Backlog Bug PRs that fix a backlog bug label Jul 19, 2025
@domdomegg
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@fluiderson
Copy link
Copy Markdown

Does this fully fix the issue with TypeScript dismissing JSONC config files? #60261 was marked as duplicate of #43121, it describes that TS also can't process JSONC in path for references. Could you include tests for this, too?

@typescript-bot
Copy link
Copy Markdown
Collaborator

With 6.0 out as the final release vehicle for this codebase, we're closing all PRs that don't fit the merge criteria for post-6.0 patches. If you think this was a mistake and this PR fits the post-6.0 patch criteria, please post to the 6.0 iteration issue with details (specifically, which PR and which patch criteria it satisfies).

Next steps for PRs:

  • For crash bugfixes or language service improvements, PRs are currently accepted at the typescript-go repo
  • Changes to type system behavior should wait until after 7.0, at which point mainline TypeScript development will resume in this repository with the Go codebase
  • Library file updates (lib.d.ts etc) continue to live in this repo or the DOM Generator repo as appropriate

@github-project-automation github-project-automation bot moved this from Not started to Done in PR Backlog Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

For Backlog Bug PRs that fix a backlog bug

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

tsconfig should support suffix .jsonc

4 participants