相关文章推荐
刀枪不入的皮带  ·  android studio ...·  2 周前    · 
小眼睛的紫菜  ·  iOS权限配置 - 简书·  5 月前    · 
坏坏的仙人掌  ·  php - laravel-soar - ...·  1 年前    · 
宽容的水煮肉  ·  js arraybuffer转string ...·  1 年前    · 
爽快的花卷  ·  终极解决TS 或者 Vetur ...·  1 年前    · 
魁梧的水龙头  ·  java.util.zip.ZipExcep ...·  1 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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

Ask Question

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?

@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) – acat 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. – james Mar 27, 2022 at 16:21

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

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.