Skip to content

tsconfig should support suffix .jsoncΒ #43121

Open

Description

@felix9

Suggestion

πŸ” Search Terms

  • json
  • jsonc
  • tsconfig

βœ… Viability Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, new syntax sugar for JS, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.

⭐ Suggestion

tsconfig should support "extends": "pkg/foo.jsonc"

Currently that will try to read node_modules/pkg/foo.jsonc.json and fail

"extends": "./foo.jsonc" works. It only fails when trying to load a config using the node-resolution codepath.

πŸ“ƒ Motivating Example

Various dev tools complain about comments in .json files.

Many json config files allow comments, so most dev tools also understand a "json-with-comments" format, and the conventional file suffix for that is .jsonc.

Some dev tools special-case tsconfig.json as jsonc, and some tools also special-case variants like tsconfig*.json, but this is awkwardly inconsistent.

Supporting the suffix .jsonc will let people ignore the special-case irregularities and gravitate toward the generic file suffix.

Q: Why not some other json variant like .json5?

A: Other json variants try to fix other "json as configuration" problems in different ways, and none of them seem particularly dominant yet. jsonc is a conservative extension to json that has a lot of support, and it's also a subset of most of the other json variants.

And the tsconfig parser is already a jsonc parser, it doesn't need to change. It just needs support for the .jsonc suffix.

πŸ’» Use Cases

Activity

  1. added
    Declined
    Suggestion
    on Mar 8, 2021
  2. RyanCavanaugh commented on Mar 8, 2021

    @RyanCavanaugh
    Member

    You're already free to name this file whatever you like; tsc -p myconfig.jsonp and other project-related commands don't require any specific naming convention. tsconfig.json is the default name and would have to remain so for compatibility reasons. Adding another extension would introduce a ton of complexity because there'd have to be tie-breaking strategies (e.g. what if we found both in the same folder, what if we found tsconfig.jsonc in one folder and tsconfig in a parent, etc).

  3. felix9 commented on Mar 8, 2021

    @felix9
    Author

    No, I know that -p can take any name. This is about "extends", it doesn't like the .jsonc suffix.

  4. added
    Bug
    and removed
    Declined
    Suggestion
    on Mar 8, 2021
  5. RyanCavanaugh commented on Mar 8, 2021

    @RyanCavanaugh
    Member

    Thanks for clarifying, you're right

  6. added
    Effort: Moderate
    on Apr 15, 2021
  7. bennycode commented on Jul 23, 2022

    @bennycode
    Contributor

    Ryan Cavanaugh (@RyanCavanaugh) this issue seems to be fixed because I just tested it with TypeScript 4.6.4 and it worked as expected πŸ˜€:

    base.jsonc

    {
      // A config file with a comment
      "compilerOptions": {
        "outDir": "myOutput",
      }
    }

    tsconfig.json

    {
      "extends": "./base.jsonc",
      "compilerOptions": {
        "lib": ["es2017"],
        "module": "commonjs",
        "moduleResolution": "node",
        "rootDir": "src",
        "strict": true,
        "target": "es6"
      }
    }

    When running npx tsc I received transpiled output in the "myOutput" directory (as specified in "base.jsonc").

    Further DX Improvements

    It's great to see that you can feed the TypeScript compiler with JSON5 or JSONC files. I wish that tsc --init would also generate a tsconfig.jsonc (or tsconfig.json5) file but it actually generates a JSON file with comments which is invalid. This behaviour decreases the UX a bit as IDEs don't like it when you put comments into plain JSON:

    WebStorm 2022.1.4

    image

    GitHub is also not a big fan of comments in JSON files and signals that in red:

    GitHub File View

    image

  8. domdomegg commented on Jul 2, 2023

    @domdomegg

    Benny Neugebauer (@bennycode) Unfortunately this issue is not fixed. This issue is about the problem that you cannot import a jsonc file from another package:

    tsconfig should support "extends": "pkg/foo.jsonc"
    Currently that will try to read node_modules/pkg/foo.jsonc.json and fail
    "extends": "./foo.jsonc" works. It only fails when trying to load a config using the node-resolution codepath.

  9. alexweej commented on Jun 25, 2024

    @alexweej

    My 2c: Not normalizing the use of the filename tsconfig.jsonc is a bit of an unnecessary microhazard. Many TSConfigs are pure JSON, and given that they have the .json filename extension, it'd seem reasonable to expect to be able to parse one using e.g. JSON.parse(...), when implementing tooling. Only potentially much later do you notice the bug when, e.g., someone brings a TSConfig scaffolded with tsc --init, full of comments, and then have to waste time going back fixing this.

    Are we at risk of eroding the simplicity of 'JSON' here, in the entire ecosystem, because of things like this? Maybe an overblown statement, but still... the answer is yes IMO :)

  10. lgarron commented on May 21, 2025

    @lgarron

    You're already free to name this file whatever you like; tsc -p myconfig.jsonp and other project-related commands don't require any specific naming convention.

    This is sort of the case, but VS Code uses tsconfig.json by default.

    I would be happy to just use tsconfig.jsonc for my own projects and let others have invalid JSON files in theirs. But this means that VS Code won't pick it up, and the TypeScript server will error on commonplace modern syntax like top-level await using its default configuration. I don't want those bogus errors in my project, and I especially don't want those errors for someone who is checking out my project. There are various options to specify how to load the TS server, but I can't find anything to specify the project file for a workspace.

    Is there any sort of workaround in TypeScript / VS Code / both that can handle this properly?

  11. Tobbe commented on Jul 13, 2025

    @Tobbe

    Another issue here that I just ran into is that you can't use the -p flag with --build. And if you do just tsc --build tsconfig.cjs.jsonc you get Cannot read file '/long/path/tsconfig.cjs.jsonc/tsconfig.json'.

  12. domdomegg commented on Jul 19, 2025

    @domdomegg

    I've put a PR up for this here: #62092

  13. added
    Domain: Module Resolution
    on Oct 16, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDomain: Module ResolutionEffort: Moderate

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions