Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

domdomegg
Copy link

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
Author

@microsoft-github-policy-service agree

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: Not started
Development

Successfully merging this pull request may close these issues.

tsconfig should support suffix .jsonc
2 participants