我有一个项目是这样安排的:
project/
client/
src/
client.ts
tsconfig.client.json
src/
index.ts
tsconfig.json
当我在project
文件夹中运行tsc -b
时,它也试图编译client
子目录,现在我明白了,如果子文件夹中有tsconfig.json
,那么--build将编译该文件夹,但在本例中,子目录的tsconfig被重命名。
结果,tsc输出错误:
error TS5083: Cannot read file 'project/client/tsconfig.json'.
如何跟踪tsc尝试加载此文件夹的原因?client
未列在顶层tsconfig的references
中,并且include
和rootDir
选项设置为仅构建src
。
我尝试过--dry build和--traceResolution,但都没有提供有用的答案。
编辑以显示我的tsconfigs:
project/tsconfig.json
{
"extends": "../../../tsconfig.base.json",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"target": "es6",
"lib": ["es2019","dom"],
"jsx": "react",
"noUnusedLocals": false
},
"include": ["./src/**/*"],
"references": [
{ "path": "shared/api" },
{ "path": "../../lib/logger" },
]
}
../../../tsconfig.base.json
{
"compilerOptions": {
"target": "es2020",
"module": "commonjs",
"moduleResolution": "node",
"rootDir": "packages",
"baseUrl": "./packages",
"lib": ["es2019"],
"strict": true,
"noUnusedLocals": true,
"noFallthroughCasesInSwitch": true,
"noImplicitReturns": true,
"esModuleInterop": true,
"allowJs": true,
"composite": true,
"inlineSources": true,
"sourceMap": true,
"incremental": true,
"skipLibCheck": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"experimentalDecorators": true,
"newLine": "lf",
"noEmitOnError": true,
},
"exclude": ["**/jest.config.js", "**/dist", "**/__mocks__/**/*", "**/coverage", "**/gulpfile.js"]
}
client/tsconfig.client.json
-如果相关,因为tsc甚至没有使用此文件
{
"compilerOptions": {
"target": "esnext",
"module": "esnext",
"strict": true,
"jsx": "preserve",
"importHelpers": true,
"moduleResolution": "node",
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"sourceMap": true,
"baseUrl": ".",
"types": [
"webpack-env",
"jest"
],
"paths": {
"@/*": [
"src/*"
]
},
"lib": [
"esnext",
"dom",
"dom.iterable",
"scripthost",
"webworker"
]
},
"include": [
"src/**/*.ts",
"src/**/*.tsx",
"src/**/*.vue",
"tests/**/*.ts",
"tests/**/*.tsx"
],
"exclude": [
"node_modules"
],
"references": [
{ "path": "../shared/api" },
{ "path": "../" }
]
}
1条答案
按热度按时间qojgxg4l1#
我发现我正在使用
npx
运行tsc
命令,因为我在monorepo中设置了工作区,所以子文件夹中有一个package.json,npm在子文件夹中拾取并第二次运行tsc命令。将我的npx命令更新为
npx --workspaces=false tsc -b
解决了这个问题。