Matan Tsuberi
Matan Tsuberi

Reputation: 511

Typescript build with project references fails with `Output file has not been built from source file` even though it was built

I'm trying to build a project that references a shared project alongside it. My configs look like:

projectA/tsconfig.json:

{
  "compilerOptions": {
    "module": "commonjs",
    "noImplicitReturns": true,
    "lib": [
      "esnext.asynciterable"
    ],
    "noUnusedLocals": true,
    "outDir": "lib",
    "sourceMap": true,
    "strict": true,
    "target": "es2017"
  },
  "compileOnSave": true,
  "include": [
    "src"
  ],
  "references": [
    {
      "path": "../shared",
      "prepend": true
    }
  ]
}

shared/tsconfig.json:

{
  "compilerOptions": {
    "outFile": "build/out.js",
    "composite": true,
    "target": "es5",
    "module": "amd",
    "declaration": true,
    "strict": true,
    "moduleResolution": "node",
    "esModuleInterop": true,
    "forceConsistentCasingInFileNames": true
  },
  "include": [
    "src"
  ]
}

running ts -b from inside projectA yields:

src/index.ts:6:24 - error TS6305: Output file '.../shared/build/out.d.ts' has not been built from source file '.../shared/src/index.ts'.

6 import DummyClass from '../../shared/src';

Even though this file is indeed created.

What am I doing wrong?

Upvotes: 27

Views: 9592

Answers (1)

Filip Sakel
Filip Sakel

Reputation: 345

For me, the solution was to run npx tsc -b on the referenced-project directory, which requires npx to tell the typescript compiler (tsc) to build (-b). You can probably add this step to your compilation pipeline.

Perhaps an easier method is to tell typescript to do that itself by running tsc -b in the npm build script of your main project (you can learn more here).

Upvotes: 8

Related Questions