Skip to content
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

TS6307: JSON files not in file list when using composite projects #905

Closed
thovden opened this issue Feb 18, 2019 · 22 comments · Fixed by #1101
Closed

TS6307: JSON files not in file list when using composite projects #905

thovden opened this issue Feb 18, 2019 · 22 comments · Fixed by #1101
Assignees
Labels
pinned don't let probot-stale close

Comments

@thovden
Copy link

thovden commented Feb 18, 2019

Expected Behaviour

Using resolveJsonModule and composite projects works as tsc does.

Note that tsc has had some issues with this that were solved in microsoft/TypeScript#25636 and that tsc works correctly now. See reproduction below.

Actual Behaviour

ERROR in ./tsloader-ts6307/tsconfig.composite.json
[tsl] ERROR
      TS6307: File 'tsloader-ts6307/src/test.json' is not in project file list. Projects must list all files or use an 'include' pattern.

Steps to Reproduce the Problem

$  git clone [email protected]:thovden/tsloader-ts6307.git
$ cd tsloader-ts6307/
$ npm i

# tsc works well for the composite config
$ npm run tsc

# webpack + ts-loader works without composite set
$ npm run works
[./src/test.json] 20 bytes {main} [built]
    + 12 hidden modules
ℹ 「wdm」: Compiled successfully.

# webpack + ts-loader fails with composite
$ npm run fails
ERROR in ts6307/tsconfig.fail.json
[tsl] ERROR
      TS6307: File 'ts6307/src/test.json' is not in project file list. Projects must list all files or use an 'include' pattern.
ℹ 「wdm」: Failed to compile.

Location of a Minimal Repository that Demonstrates the Issue.

https://github.com/thovden/tsloader-ts6307

@thovden
Copy link
Author

thovden commented Feb 19, 2019

I get these intermittently in VS Code as well, so perhaps here is some funkiness in the typescript servicehost that affects both ts-loader and VS Code

image

@johnnyreilly
Copy link
Member

Possibly.... Have you bumped on this @andrewbranch?

@andrewbranch
Copy link
Contributor

Hmm, nope, that's new to me. Would be happy to take a look at it sometime, but I'm about to be traveling (without a computer) for the next few weeks 🙈

@johnnyreilly
Copy link
Member

Have great travels! It's good to be away from the keyboard every now and then 😁

@stale
Copy link

stale bot commented Apr 21, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Apr 21, 2019
@andrewbranch
Copy link
Contributor

@stalebot relax, I'll put it on my to-do list

@webberwang
Copy link

webberwang commented May 4, 2019

I'm getting this as well:

is not in project file list. Projects must list all files or use an 'include' pattern.

I have

include: ['src/**/*', 'src/**/*.json]

set inside tsconfig.json, and the setting is working for tsc but not ts-loader.

@andrewbranch
Copy link
Contributor

This appears to be a TypeScript bug here: https://github.com/microsoft/TypeScript/blob/eeba30afc81e2c7c8a34a2deb0d4d2375a1c21f6/src/compiler/program.ts#L2771-L2774

I think either the JSON file should be in the program’s rootFiles when resolveJsonModule is true (there are a few different places that prevent this from happening), or sourceFileMayBeEmitted() is returning true for the JSON file when it should be returning false. (To clarify—it’s definitely returning true, I think it's possible it should be returning false.)

Here's a minimal repro:

Compile with:

import * as ts from 'typescript';

const commandLine = ts.parseJsonSourceFileConfigFileContent(ts.readJsonConfigFile('tsconfig.json', ts.sys.readFile), ts.sys, '.');
console.log(commandLine.fileNames);

const program = ts.createProgram({
  rootNames: commandLine.fileNames,
  options: commandLine.options,
});

const diagnostics = program.getOptionsDiagnostics();

console.log(ts.formatDiagnostics(diagnostics, {
  getCanonicalFileName: fileName => fileName,
  getCurrentDirectory: ts.sys.getCurrentDirectory,
  getNewLine: () => '\n',
}));

tsconfig.json

{
  "compilerOptions": {
    "moduleResolution": "node",
    "target": "es5",
    "composite": true,
    "resolveJsonModule": true
  },
  "include": [
    "*.ts",
    "*.json"
  ]
}

foo.ts

import * as foo from './foo.json';

foo.json

{}

/cc @sheetalkamat what's the expected behavior here?

@sheetalkamat
Copy link
Contributor

@andrewbranch This works with tsc but not with the sample repro code you gave because your base path is not resolved? (changing that to say 'c:/temp/test2' works). That's because https://github.com/microsoft/TypeScript/blob/master/src/compiler/commandLineParser.ts#L2729 expects basePath to be the first thing in the json matching pattern

@andrewbranch
Copy link
Contributor

Ah yes, that does fix my repro. I think ts-loader must be making a similar mistake, because the JSON files were definitely not in the program. This really helps narrow it down, thanks!

@stale
Copy link

stale bot commented Jul 19, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@xtianus79
Copy link

this is still an issue

@mvargeson
Copy link

Has anybody come across a workaround for this issue (other than not using composite projects)?

@andrewbranch
Copy link
Contributor

I’ll try to take a look at this over the weekend.

@johnnyreilly
Copy link
Member

You are a prince among men @andrewbranch 🤴

berickson1 added a commit to berickson1/ts-loader that referenced this issue May 6, 2020
Ensure that json files are resolved if resolveJsonModule flag is set in tsconfig
@berickson1
Copy link
Contributor

I spent a couple hours digging into this after @mvargeson shared with me. Ideally you'd be able to use the regex generated internally by the typescript compiler instead of generating our own but I couldn't find a way that it was exposed.

johnnyreilly pushed a commit that referenced this issue May 7, 2020
…#1101)

* Fix #905
Ensure that json files are resolved if resolveJsonModule flag is set in tsconfig

* Add test

* PR Comments
berickson1 added a commit to berickson1/ts-loader that referenced this issue May 22, 2020
…trong#905) (TypeStrong#1101)

* Fix TypeStrong#905
Ensure that json files are resolved if resolveJsonModule flag is set in tsconfig

* Add test

* PR Comments
kamontat added a commit to kamontat/kcutils that referenced this issue Jan 21, 2022
@mrcaidev
Copy link

Still an issue

@malshoff
Copy link

malshoff commented Feb 2, 2023

Bump, ended up here from Google and it is still an issue.

@SalahAdDin
Copy link

SalahAdDin commented Feb 9, 2023

It is still an issue.

@kkoudelka
Copy link

Any updates on this?

rangoo94 added a commit to kubeshop/testkube-dashboard that referenced this issue Jul 11, 2023
rangoo94 added a commit to kubeshop/testkube-dashboard that referenced this issue Jul 13, 2023
rangoo94 added a commit to kubeshop/testkube-dashboard that referenced this issue Jul 13, 2023
…cies (#774)

* feat: update dependencies, delete Cypress and add Playwright tests as workspace
   Relates to: kubeshop/testkube#3856
* feat: use default Webpack minification process, along with sourcemaps
* fix: ignore generated Playwright results for Prettier
* feat: update Monaco Editor
* add "test/dashboard-e2e" to tsconfig file
* chore: delete unused terser-webpack-plugin
* fixup chore: delete unused terser-webpack-plugin
* feat: use tsconfig-paths-webpack-plugin instead of deprecated craco-alias
* feat: avoid installing Chromium in the Docker image
* feat: add TypeScript types to Playwright tests
* fix: replace JSON fixtures with TS
   @see {@link TypeStrong/ts-loader#905}
* fix: run unit tests with proper modules mapping
* fixup make "husky" optional for prepare script
* fix: increase max timeout for waiting for Vercel preview
* fix: lock Playwright version to v1.32.3
* fix: avoid segmentation fault in Stylelint
* chore: avoid separate tsconfig for test files
* fixup spec types
@pfdgithub
Copy link

microsoft/TypeScript#25636 (comment)

{
  "include": ["./src/**/*", "./src/**/*.json"],
}

@igmrrf
Copy link

igmrrf commented Nov 16, 2023

{
"compilerOptions": {
"module": "CommonJS",
"target": "es6",
"sourceMap": true,
"moduleResolution": "node",
"esModuleInterop": true,
"resolveJsonModule": true, // Adding this line
},
"exclude": ["node_modules", "build"]
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pinned don't let probot-stale close
Projects
None yet
Development

Successfully merging a pull request may close this issue.