Skip to content

include patterns need to specifiy .json extension in composite projects despite resolveJsonModule: true #55366

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

Closed
eps1lon opened this issue Aug 14, 2023 · 3 comments · Fixed by #55389
Assignees
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue

Comments

@eps1lon
Copy link
Contributor

eps1lon commented Aug 14, 2023

🔎 Search Terms

include composite resolveJsonModule

Reopening of #25636 which doesn't seem to have fixed all problems reported in that issue

🕗 Version & Regression Information

This is the behavior in every version I tried (up until 4.1)

⏯ Playground Link

https://github.com/eps1lon/ts-references-json

💻 Code

import data from "./data.json";

export default { data };
{
  "extends": "../tsconfig.base.json",
  "compilerOptions": {
    "composite": true
  },
  "include": ["./**/*"]
}

🙁 Actual behavior

$ tsc --build tsconfig.json
feature-two/index.ts:1:18 - error TS6307: File '/Users/sebastian.silbermann/ts-references-json/feature-two/data.json' is not listed within the file list of project '/Users/sebastian.silbermann/ts-references-json/feature-two/tsconfig.json'. Projects must list all files or use an 'include' pattern.

1 import data from "./data.json";
                   ~~~~~~~~~~~~~


Found 1 error.

Explicitly adding .json to include like #25636 (comment) suggested works also but is unintuitive since the extension is only required in composite projects.

🙂 Expected behavior

Compiles just fine without having to add another include pattern using .json.

@RyanCavanaugh RyanCavanaugh added the Needs Investigation This issue needs a team member to investigate its status. label Aug 14, 2023
@sheetalkamat
Copy link
Member

The json files are not included by include pattern unless you specify the ".json" extension so per your include pattern in tsconfig the root files is "index.ts" and does not include "data.json". Composite wants you to list all input files and data.json is not part of your config and hence error. This is working as per design.

When you look at explain files it shows that "data.json" is included only through import and not any of the config file rules.

c:\temp\ts-references-json>node c:\TypeScript\built\local\tsc.js -b -v --explainFiles
[10:54:51 AM] Projects in this build:
    * feature-two/tsconfig.json
    * feature-one/tsconfig.json
    * tsconfig.json

[10:54:51 AM] Project 'feature-two/tsconfig.json' is out of date because output file 'feature-two/tsconfig.tsbuildinfo' does not exist

[10:54:51 AM] Building project 'c:/temp/ts-references-json/feature-two/tsconfig.json'...

feature-two/index.ts:1:18 - error TS6307: File 'c:/temp/ts-references-json/feature-two/data.json' is not listed within the file list of project 'c:/temp/ts-references-json/feature-two/tsconfig.json'. Projects must list all files or use an 'include' pattern.

1 import data from "./data.json";
                   ~~~~~~~~~~~~~

../../TypeScript/built/local/lib.d.ts
  Default library for target 'es5'
../../TypeScript/built/local/lib.es5.d.ts
  Library referenced via 'es5' from file '../../TypeScript/built/local/lib.d.ts'
../../TypeScript/built/local/lib.dom.d.ts
  Library referenced via 'dom' from file '../../TypeScript/built/local/lib.d.ts'
../../TypeScript/built/local/lib.webworker.importscripts.d.ts
  Library referenced via 'webworker.importscripts' from file '../../TypeScript/built/local/lib.d.ts'
../../TypeScript/built/local/lib.scripthost.d.ts
  Library referenced via 'scripthost' from file '../../TypeScript/built/local/lib.d.ts'
../../TypeScript/built/local/lib.decorators.d.ts
  Library referenced via 'decorators' from file '../../TypeScript/built/local/lib.es5.d.ts'
../../TypeScript/built/local/lib.decorators.legacy.d.ts
  Library referenced via 'decorators.legacy' from file '../../TypeScript/built/local/lib.es5.d.ts'
feature-two/data.json
  Imported via "./data.json" from file 'feature-two/index.ts'
feature-two/index.ts
  Matched by include pattern './**/*' in 'feature-two/tsconfig.json'
[10:54:54 AM] Project 'feature-one/tsconfig.json' can't be built because its dependency 'feature-two/tsconfig.json' has errors

You can fix this as suggested in #25636 by either adding files or include with json pattern.

We also have test case

[96msrc/src/index.ts[0m:�[93m1[0m:�[93m19[0m -[91merror[0m[90m TS6307: �[0mFile '/src/src/hello.json' is not listed within the file list of project '/src/tsconfig_withInclude.json'. Projects must list all files or use an 'include' pattern.
to show this. And way to fix by or

@sheetalkamat sheetalkamat added Working as Intended The behavior described is the intended behavior; this is not a bug and removed Needs Investigation This issue needs a team member to investigate its status. labels Aug 15, 2023
@eps1lon
Copy link
Contributor Author

eps1lon commented Aug 15, 2023

While this may be what you intended when implementing, it's not intuitive from a user perspective.

@sheetalkamat
Copy link
Member

Given that data.json will be copied to your outDir it seems correct that it should be listed in your config.

But while writing above comment i realised, your config doesnt have outDir. So it seems like a bug where data.json shouldnt need to be listed?

Note that if we change this, it also means that not listing data.json has implications on tsc --build only root files specified by config are checked if anything changed with respect to output and with this it will not rebuild project if data,json gets updated after project was successfully built.

@sheetalkamat sheetalkamat added Needs Investigation This issue needs a team member to investigate its status. and removed Working as Intended The behavior described is the intended behavior; this is not a bug labels Aug 15, 2023
sheetalkamat added a commit that referenced this issue Aug 15, 2023
…y in the config since they will not be emitted

Fixes #55366
@sheetalkamat sheetalkamat added Fix Available A PR has been opened for this issue Bug A bug in TypeScript and removed Needs Investigation This issue needs a team member to investigate its status. labels Aug 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A bug in TypeScript Fix Available A PR has been opened for this issue
Projects
None yet
3 participants