TypeScript 可能的回归:resolveJsonModule项目必须列出所有文件或使用'include'模式,

l7mqbcuq  于 6个月前  发布在  TypeScript
关注(0)|答案(5)|浏览(67)

TypeScript版本: 3.7.0-dev.20190912
搜索词:

resolveJsonModuleProjects must list all files or use an 'include' pattern

代码

tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "outDir": "./dist",
    "rootDir": "./src",
    "strictNullChecks": true,
    "resolveJsonModule": true
  },
  "include": ["src/**/*.ts", "src/**/*.json"],
  "references": []
}

tsconfig.base.json

{
  "compilerOptions": {
    "module": "commonjs",
    "target": "es2017",
    "lib": ["es2017"],
    "composite": true,
    "esModuleInterop": true,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "noUnusedLocals": true,
    "noUnusedParameters": true,
    "sourceMap": true,
    "skipLibCheck": true
  }
}

预期行为:

resolveJsonModule 被打开,并且 json 文件已经被包含在 includes 数组中时,我应该能够顺利地导入 json 文件。

实际行为:

当我使用上述 tsconfig 选项,并包含一个 json 文件时,我得到了以下错误:

相关问题:

#31181

tmb3ates

tmb3ates1#

我们需要一个复现案例来调查这个问题。

mcdcgff0

mcdcgff02#

我在这个分支上也看到了相同的情况。

yjghlzjz

yjghlzjz3#

@razzeeehttps://github.com/elm-tooling/elm-language-server/blob/rank/tsconfig.json#L17 不够充分。您必须明确列出要包含的json文件。将其更改为 "include": ["src", "src/**/*.json"] 可以解决该问题。

nimxete2

nimxete24#

Thank you, that fixes compilation, after restarting VSCode

arknldoa

arknldoa5#

@razzeeehttps://github.com/elm-tooling/elm-language-server/blob/rank/tsconfig.json#L17 is not sufficient. You have to explicitly list json files to be included. Changing that to "include": ["src", "src/**/*.json"] fixes the issue.
Why do I need to do that even I have --resolveJsonModule on?
If a glob pattern doesn’t include a file extension, then only files with supported extensions are included (e.g. .ts, .tsx, and .d.ts by default, with .js and .jsx if allowJs is set to true).
In the document of includes . I think .json should be included too when resolveJsonModule is on.

相关问题