Ts-loader: TS6307: JSON files not in file list when using composite projects

Created on 18 Feb 2019  ·  16Comments  ·  Source: TypeStrong/ts-loader

Expected Behaviour

Using resolveJsonModule and composite projects works as tsc does.

Note that tsc has had some issues with this that were solved in https://github.com/Microsoft/TypeScript/issues/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

pinned

Most helpful comment

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

All 16 comments

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

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

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 🙈

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

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.

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

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.

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?

@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

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!

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.

this is still an issue

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

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

You are a prince among men @andrewbranch 🤴

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.

Was this page helpful?
0 / 5 - 0 ratings