Skip to content

TS5055: Typescript includes files in "dist" folder for compilation when rootDir is not ./ but ./src even after explicitly adding "dist" to excludeΒ #58090

@calebpitan

Description

@calebpitan

πŸ”Ž Search Terms

TS5055, rootDir, outDir, exclude

πŸ•— Version & Regression Information

TypeScript 5.4.4

⏯ Playground Link

https://github.com/calebpitan/zne-repro

No response

πŸ’» Code

// Your code here

yarn install

cd ./libs/common

yarn tsc --build tsconfig.json

This fails with the TS5055 error and since it is the base of every other dependent workspace/lib package build for the others fail too, except I rimraf dist which works fine if I just want to do a one time build, but doesn't if I have to build-watch.

NOTE: Initial build always works fine, subsequent builds are the ones that fail.

πŸ™ Actual behavior

Includes output files (mostly declaration output files) as part of input even after explicitly excluding them. This doesn't happen when I change rootDir from ./src to ./ (but unfortunately this creates an unwanted effect of emitting output to dist/src instead of just dist so I'd like to retain rootDir as ./src rather than ./)

πŸ™‚ Expected behavior

Should not include output files in input files especially after explicitly excluding them

Additional information about the issue

tsconfig.json

{
  "extends": "../../tsconfig.base.json",
  "compilerOptions": {
    "composite": true,
    "outDir": "./dist",
    "rootDir": "./src",
    "baseUrl": "."
  },
  "include": ["src/**/*"],
  "exclude": ["node_modules", "dist"]
}

tsconfig.base.json

{
  "compilerOptions": {
    "module": "commonjs",
    "moduleResolution": "node",
    "declaration": true,
    "removeComments": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "allowSyntheticDefaultImports": true,
    "esModuleInterop": true,
    "target": "ES2022",
    "sourceMap": true,
    "outDir": "./dist",
    "baseUrl": "./",
    "isolatedModules": true,
    "incremental": true,
    "skipLibCheck": true,
    "strict": true,
    "strictNullChecks": true,
    "strictPropertyInitialization": false,
    "noImplicitAny": false,
    "strictBindCallApply": false,
    "forceConsistentCasingInFileNames": false,
    "noFallthroughCasesInSwitch": false,
    "resolveJsonModule": true,
    "allowJs": false,
    "jsx": "react",
    "typeRoots": ["./@types", "node_modules/@types"],
    "paths": {
      "@/module/*": ["./apps/customer/src/module/v1/*"]
    }
  },
  "watchOptions": {
    "excludeDirectories": ["*/**/node_modules", "*/**/dist", "libs/**/dist"]
  }
}

First compilation runs smoothly, subsequent compilations error with:

error TS5055: Cannot write file '/Users/calebpitan/source/work/company/project/libs/customer/dist/constant.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/calebpitan/source/work/company/project/libs/customer/dist/index.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/calebpitan/source/work/company/project/libs/customer/dist/prisma.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/calebpitan/source/work/company/project/libs/customer/dist/prisma.enum.d.ts' because it would overwrite input file.

error TS5055: Cannot write file '/Users/calebpitan/source/work/company/project/libs/customer/dist/prisma.module.d.ts' because it would overwrite input file.

Metadata

Metadata

Assignees

No one assigned

    Labels

    QuestionAn issue which isn't directly actionable in code

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions