27

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?

3
  • 3
    Did you find a solution to this? Commented Jan 4, 2022 at 1:45
  • @james I too am running into this. I don't have a full solution, but it appears circular references may be involved. See here for a start (the page I was on before my search led to here) Commented Mar 27, 2022 at 2:25
  • I've actually changed my approach here if this helps anyway. I do have a shared library project to a similar setup, but as a far of my ProjectA I've added a build.sh. I adjusted my package.json to include a "build" script that executes build.sh. Build.sh then copies my needed libraries into project A and runs a webpack with a tsloader so i'm actually pulling these into the project locally. Probably not the greatest but it got me moving. Commented Mar 27, 2022 at 16:21

1 Answer 1

10

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).

Sign up to request clarification or add additional context in comments.

2 Comments

This is such a save. Great thanks!
can you clarify "running tsc -b in the npm build script of your main project" ??

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.