TS6307 error when building with tsup in monorepo package, but tsc works fine
- Dominant language
- TypeScript
- Stars
- 11.3k
- Forks
- 275
- PR merge metrics
- No merged PRs in 30d
Description
**Description:**
I'm working in a monorepo setup. In my package, I have the following structure:
```
package
├── src/
│ ├── index.ts
│ └── ref.ts
├── package.json
├── tsconfig.json
```
My `tsconfig.json` includes:
```json
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"composite": true,
"rootDir": "./src",
"moduleResolution": "node",
"outDir": "dist"
},
"include": ["src/**/*"]
}
```
My build script in `package.json` is:
```json
"build": "tsup src/index.ts --clean --format cjs,esm --dts --tsconfig ./tsconfig.json"
```
When I run `npm run build`, I get the following error:
```
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.
```
However, running `npx tsc -p tsconfig.json` works perfectly and generates the expected declaration files.
---
**What I've tried:**
- Changing `moduleResolution` between `node` and `bundler`
- Adjusting the `include` pattern
- Cleaning the `dist` and `.tsbuildinfo` files
- Upgrading `tsup` and `typescript`
- Restarting VS Code
---
**Expected behavior:**
`tsup` should build the package and generate declaration files without TS6307 errors, just like `tsc` does.
---
**Actual behavior:**
`tsup` fails with TS6307, but `tsc` works.
---
**Environment:**
- tsup version: v8.5.0
- typescript version: v5.9.2
- Node.js version: v22.19.0
---
**Additional context:**
Is there a workaround or recommended way to use `tsup` for both JS and declaration file generation in this scenario?
Contributor guide
Research direction
Reproduce the failure with the package's `package.json` build script and `tsconfig.json`, using `src/index.ts` and its `src/ref.ts` import. Compare `tsup src/index.ts --clean --format cjs,esm --dts --tsconfig ./tsconfig.json` with `npx tsc -p tsconfig.json`. Done means the tsup build completes and generates the expected declaration files without TS6307.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- build-system
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100