TypeScript版本: 3.7.0-dev.20190912
搜索词:
resolveJsonModule
Projects 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 文件时,我得到了以下错误:
相关问题:
5条答案
按热度按时间tmb3ates1#
我们需要一个复现案例来调查这个问题。
mcdcgff02#
我在这个分支上也看到了相同的情况。
yjghlzjz3#
@razzeeehttps://github.com/elm-tooling/elm-language-server/blob/rank/tsconfig.json#L17 不够充分。您必须明确列出要包含的json文件。将其更改为
"include": ["src", "src/**/*.json"]
可以解决该问题。nimxete24#
Thank you, that fixes compilation, after restarting VSCode
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 whenresolveJsonModule
is on.