Repository navigation
Description
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.
Activity
RyanCavanaugh commentedon Mar 8, 2021
You're already free to name this file whatever you like;
tsc -p myconfig.jsonpand other project-related commands don't require any specific naming convention.tsconfig.jsonis 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).felix9 commentedon Mar 8, 2021
No, I know that
-pcan take any name. This is about "extends", it doesn't like the.jsoncsuffix.RyanCavanaugh commentedon Mar 8, 2021
Thanks for clarifying, you're right
bennycode commentedon Jul 23, 2022
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 tscI 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 --initwould also generate atsconfig.jsonc(ortsconfig.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
GitHub is also not a big fan of comments in JSON files and signals that in red:
GitHub File View
chore: use jsonc extension for commented tsconfig
chore: use jsonc extension for commented tsconfig
chore: use jsonc extension for commented tsconfig
domdomegg commentedon Jul 2, 2023
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:
alexweej commentedon Jun 25, 2024
My 2c: Not normalizing the use of the filename
tsconfig.jsoncis a bit of an unnecessary microhazard. Many TSConfigs are pure JSON, and given that they have the.jsonfilename 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 withtsc --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 :)
lgarron commentedon May 21, 2025
This is sort of the case, but VS Code uses
tsconfig.jsonby default.I would be happy to just use
tsconfig.jsoncfor 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?
Tobbe commentedon Jul 13, 2025
Another issue here that I just ran into is that you can't use the
-pflag with--build. And if you do justtsc --build tsconfig.cjs.jsoncyou getCannot read file '/long/path/tsconfig.cjs.jsonc/tsconfig.json'.Fix tsconfig import extensions
domdomegg commentedon Jul 19, 2025
I've put a PR up for this here: #62092