Monorepo, References: Output file has not been built from source file (TS6305)

See original GitHub issue

Current behavior

It throws

TS6305: Output file 'C:/Users/xnerhu/Desktop/fork-ts-checker-webpack-plugin-repro/packages/foo/src/index.d.ts' has
not been built from source file 'C:/Users/xnerhu/Desktop/fork-ts-checker-webpack-plugin-repro/packages/foo/src/index.ts'

Expected behavior

It should not throw the error.

Steps to reproduce the issue

Import a package with typings referencing source files only (not prebuilt declarations). In VSCode it works.

Example:

package/foo/index.ts

import * as test from 'bar'

package/bar/package.json

{
  "name": "bar",
  "main": "build/main.js",
  "types": "src",
}

Issue reproduction repository

https://github.com/xnerhu/fork-ts-checker-webpack-plugin-repro

Environment

  • fork-ts-checker-webpack-plugin: ^5.2.1
  • typescript: ^4.0.5
  • eslint: none
  • webpack: ^5.3.2
  • os: Windows 10

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:5
  • Comments:6

github_iconTop GitHub Comments

3reactions
casamia918commented, Jan 9, 2022

Tips to create-react-app users.

At the beginning, I’ve been using CRA version 4.0.3.

In create-react-app version 4.0.3, they internally use fork-ts-checker-webpack-plugin version 4.1.6, which has no options of build: true. (see package.json )

I tried to manually set fork-ts-checker-webpack-plugin version to 5 by using package.json > resolutions field. But as the fork-ts plugin’s option signature is changed, it failed with compile error.

So, I have no choice without upgrading cra v5.

(You may be facing unexpected error while upgrading cra v5. This is up to you. In my case, I’ve faced only 2 errors. )

fork-ts-checker-webpack-plugin introduced options.typescript.build at version 5

In create-react-app version 5, fork-ts-checker-webpack-plugin version is upgrade to ^6.5.0, so you can use build option. (see package.json )

But CRA team did not set build:true option. So, if you are not ejecting cra, you should manually override the fork-ts-checker-webpack-plugin option.

In my case, I’m using react-app-rewired & customize-cra to override webpack config of CRA without ejecting.

So I add tiny overrideFunc to set build:true manually.


module.exports = {
 webpack: override(
 ...
  (config) => {
    const forkTsPlugInInstances = config.plugins.find(
      (p) => p.constructor.name === 'ForkTsCheckerWebpackPlugin',
    );
    if (!forkTsPlugInInstances) return config;

    forkTsPlugInInstances.options.typescript.build = true;

    return config;
  },
 ...
)

}

1reaction
piotr-olescommented, Nov 2, 2020

Hi! Did you tried build: true option?

Read more comments on GitHub >

github_iconTop Results From Across the Web

TypeScript project with references - Stack Overflow
Found this when searching for "typescript references has not been built from source file". My mistake was that I was running tsc -p ......
Read more >
You might not need TypeScript project references - Turborepo
If the referenced project produces an outFile , the output file .d.ts file's declarations will be visible in this project; Running build mode...
Read more >
Typescript outDir ignored in monorepo : WEB-44572
ts' has not been built from source file 'E:/downloads/project-references-demo/core/utilities.ts'. reported when compiling. No files are generated for me in core ...
Read more >
TypeScript Project References - Ionic Framework
Using the same methodology and similar configuration we get TS6305 Output file "X.d.ts" has not been built from source file "X.ts".
Read more >
Typescript project references not compiling.
However, visual studio does not build those projects now. ... Since these output files are used to compile the main project, the main...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found