#1364·tsup

在 monorepo 包中使用 tsup 构建时出现 TS6307 错误,但 tsc 运行正常

作者: ktlshya创建于 2025年9月13日更新于 2026年3月13日

描述:

我正在使用一个单一仓库的设置。在我的包中,我有以下结构:

package
├── src/
│   ├── index.ts
│   └── ref.ts
├── package.json
├── tsconfig.json

我的 tsconfig.json 包括:

json
{
  "extends": "../../tsconfig.json",
  "compilerOptions": {
    "composite": true,
    "rootDir": "./src",
    "moduleResolution": "node",
    "outDir": "dist"
  },
  "include": ["src/**/*"]
}

我的 package.json 中的构建脚本是:

json
"build": "tsup src/index.ts --clean --format cjs,esm --dts --tsconfig ./tsconfig.json"

当我运行 npm run build 时,会出现以下错误:

error TS6307: File '/package/src/ref.ts' is not listed within the file list of project ''. Projects must list all files or use an 'include' pattern.

然而,运行 npx tsc -p tsconfig.json 可以完美工作,并生成预期的声明文件。