-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Building composite project with resolveJsonModule fails #25636
Comments
we should allow |
@mhegazy Is assumption that we shouldnt include them through include pattern of config file though? |
yeah. i think that would be a bigger breaking change. |
@strax @sheetalkamat @mhegazy Is this problem fixed in TypeScript 3.1.1? I have tried to use TypeScript 3.1.1 in the repro project, TypeScript gives the following error:
It seems to this problem is still exist. |
@cockscomb you need to have files clause to have the json file( |
@sheetalkamat We ran into a similar issue as @cockscomb. {
"$schema": "http://json.schemastore.org/tsconfig",
"compilerOptions": {
"rootDir": "src",
"composite": true,
"target": "es2017",
"outDir": "dist"
},
"references": [
...
],
"include": [
"**/*"
]
} None of the following works:
Do we have to use |
If I am reading the tests added as part of 49ac60f correctly, then yes, JSON files must be explicitly listed in @sheetalkamat what is the reasoning behind this requirement/limitation? Would you accept a pull request modifying the behavior of |
We do not want to add json files in compilation accidently and want users to explicitly specify them instead of using the include/exclude pattern. |
@sheetalkamat Thank you for the comment, I see your point. Let me explain my use case. In LoopBack, we have a concept of a data source - a class providing access to a database, web service, etc. An application (a LoopBack/TypeScript project) can have multiple datasources. Each datasource is implemented in two files: a JSON file with the configuration (to make it easy to edit programmatically) and a TypeScript file exporting the datasource class. The TypeScript code in import * as config from './db.datasource.json';
export class DbDataSource extends juggler.DataSource {
constructor() {
super(dsConfig);
}
} JSON config in {
"name": "db",
"connector": "memory"
} Relevant parts of tsconfig (we are not using project references yet):
Now back to the topic of this issue:
If my first two arguments above are not convincing enough and/or there are other reasons explaining why JSON files must be treated differently in composite vs. non-composite projects: Can we at least allow JSON files to be specified via an explicit pattern in
|
The issue isn't about including json in compiling but its about not specifying the json file in the list of inputs. Composite projects need explicitly include all files in the compilation as referencing projects need to be able to identify its all output. Adding @DanielRosenwasser for opinion. The requirement you are suggesting is quite a work and need to be handled by multiple hosts as well (since it needs to integrate with our readDirectory interface as well). Apart from that right now if you have js and ts file with same name in location, the jsFile is ignored(since its lower in priority than ts file and that means that behavior needs change for json modules as well) |
Ok I spoke too soon. I think we are able to achieve what you want and I will put up PR for this. Also discussed with @DanielRosenwasser that including json file even if there is ts file with same name is ok. (since its not output of ts file anyways) |
Thank you @sheetalkamat for finding a solution and landing it via #27844 🙇 I think it would be great to describe the interaction between |
This works for me: {
"include": ["./src/**/*", "./src/**/*.json"],
} |
There is still the issue of JSON files in |
Few additional tricks are required: 1) Due to resolveJsonModule being true, we need to explicitly add json files to "include" (microsoft/TypeScript#25636) 2) "clean" script must remove *.tsbuildinfo files when deleting build artifacts (otherwise build will be skipped)
Listing JSON files in files section of tsconfig works for me ~ Thx @bajtos |
This is still an issue |
I'm experiencing the same issue my project is setup as followed:
My main entry configuration file is
Although I've listed it explicitly through {
"extends": "../../tsconfig.base.json",
"files": [
"./index.ts",
"../consts.json",
],
"references": [
{"path": "../worker"},
{"path": "../utils"}
]
} |
I was spending time fiddling around with this until I realized it was a TS issue. It is confusing and not intuitive to have to write something like {
"include": ["./src/**/*", "./src/**/*.json"],
} |
@trusktr's solution worked, but I had to restart my IDE. Why is this issue closed? |
The addition of the new composite attribute sounds reasonable and justified to allow nested config but seriously, guys, I think you are breaking a lot of projects right now!! |
Just add this to the root of
|
this still an issue 2021 ... why this been closed? |
@zerubeus & anyone reading this in the future - I just checked after running into this issue now, it seem like @TsaiTsaiChieh 's PR above fixes the issue by allowing a glob pattern in tsconfig's include property: include: ["**/*.json"] TsaiTsaiChieh/never-stray@ac22f38 Confirmed working on typescript 4.5.4 |
No any of the given solutions works for us. |
TypeScript Version: 3.0.0-rc
Search Terms:
resolveJsonModule, composite project, TS6307
Code
Repro at https://github.com/strax/ts-3-json-bug-repro
Expected behavior:
With
composite: true
andresolveJsonModule: true
set intsconfig.json
, JSON modules are resolved in the compilation like they are when thecomposite
compiler option is not set.Actual behavior:
Running
tsc
gives the following error:In addition, trying to include
src/hello.json
in thefiles
property fails withPlayground Link:
Related Issues:
The text was updated successfully, but these errors were encountered: