title: Issues building a TypeScript monorepo project
body: <p>I have a fairly simple mono repo. It is available on GitLab
  <a href="https://gitlab.com/remcohaszing/koas" rel="noreferrer">here</a>. This uses yarn workspaces, TypeScript, Jest, <code>ts-jest</code>
  and ESLint with <code>eslint-plugin-import</code>.</p>
  
  <p>I am trying to properly build the project packages using TypeScript. Previously I was just
  publishing the TypeScript files alongside their JavaScript code in the same directory.</p>
  
  <p>My attempt to build the project is available in a GitLab merge request
  <a href="https://gitlab.com/remcohaszing/koas/merge_requests/27" rel="noreferrer">here</a></p>
  
  <p>Now the repository follows the following layout:</p>
  
  <pre><code> |- example/
   |   |- index.ts
   |   |- package.json
   |   `- tsconfig.json
   |- packages/
   |   |- koas-core/
   |   |   |- src/
   |   |   |   `- index.ts
   |   |   |- package.json
   |   |   `- tsconfig.json
   |   |- koas-status-code/
   |   |   |- src/
   |   |   |   `- index.ts
   |   |   |- package.json
   |   |   `- tsconfig.json
   |   `- more similar workspaces…
   |- package.json
   |- tsconfig.json
   `- more configuration files…
  </code></pre>
  
  <p>Some packages depend on each other. I have managed to get Jest tests and <code>eslint-plugin-import</code> to
  work with this setup, but I’m having trouble building the project.</p>
  
  <p>The root <code>tsconfig.json</code> looks like this:</p>
  
  <pre><code>{
    "compilerOptions": {
      "baseUrl": ".",
      "composite": true,
      "declaration": true,
      "module": "commonjs",
      "noEmit": true,
      "resolveJsonModule": true,
      "target": "esnext",
      "paths": {
        "koas-*": ["packages/koas-*/src"]
      }
    },
    "exclude": ["**/*.test.ts"]
  }
  </code></pre>
  
  <p>The workspace <code>tsconfig.json</code> files look like this:</p>
  
  <pre><code>{
    "extends": "../../tsconfig.json",
    "compilerOptions": {
      "rootDir": "src",
      "outDir": "lib"
    }
  }
  </code></pre>
  
  <p>Each workspace has a <code>prepack</code> script defined in <code>package.json</code> that looks like this:</p>
  
  <pre><code>{
    "scripts": {
      "prepack": "tsc --noEmit false"
    }
  }
  </code></pre>
  
  <p>The <code>main</code> field refers to <code>lib</code>.</p>
  
  <p>If I run <code>yarn workspace koas-status-code prepack</code>, I get the following error:</p>
  
  <pre><code>$ tsc --noEmit false
  error TS6059: File 'koas/packages/koas-core/src/SchemaValidationError.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/SchemaValidationError.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/createDefaultValidator.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/createDefaultValidator.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/createMatcher.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/createMatcher.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/index.ts' is not under 'rootDir' 'koas/packages/koas-status-code'. 'rootDir' is expected to contain all source files.
  
  error TS6059: File 'koas/packages/koas-core/src/index.ts' is not under 'rootDir' 'koas/packages/koas-status-code/src'. 'rootDir' is expected to contain all source files.
  
  error TS6307: File 'koas/packages/koas-core/src/SchemaValidationError.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
  
  error TS6307: File 'koas/packages/koas-core/src/createDefaultValidator.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
  
  error TS6307: File 'koas/packages/koas-core/src/createMatcher.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
  
  error TS6307: File 'koas/packages/koas-core/src/index.ts' is not listed within the file list of project 'koas/packages/koas-status-code/tsconfig.json'. Projects must list all files or use an 'include' pattern.
  
  
  Found 12 errors.
  </code></pre>
  
  <p>I have also tried this <code>tsconfig.json</code> for <code>koas-status-code</code>:</p>
  
  <pre><code>{
    "extends": "../../tsconfig.json",
    "include": ["src"],
    "references": [{ "path": "../koas-core" }],
    "compilerOptions": {
      "outDir": "lib"
    }
  }
  </code></pre>
  
  <p>This builds the workspace, but still gives me the following error:</p>
  
  <pre><code>$ tsc --noEmit false
  src/index.ts:1:23 - error TS6305: Output file '/home/remco/Projects/koas/packages/koas-core/lib/src/index.d.ts' has not been built from source file '/home/remco/Projects/koas/packages/koas-core/src/index.ts'.
  
  1 import * as Koas from 'koas-core';
                          ~~~~~~~~~~~
  
  
  Found 1 error.
  </code></pre>
  
  <p>How do I fix this?</p>