TypeStrong / TypeStrong/ts-loader

Project References won't work if extends config file

Open
#1,035 18 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
TypeScript
Stars
3.5k
Forks
439
Avg merge
17h 17m
Merged PRs (30d)
2

Description

Background

ts-load version: 6.2.1
webpack version: 4.28.3
webpack-cli version: 3.3.10
tyepscript version: 3.7.2

Given the following config files:

  1. tsconfig.json:
{
    "extends": "../tsconfig-global.json",
    "compilerOptions": {
        "outDir": "./dist",
        "strictNullChecks": false,
        "rootDir": "./src",
        "tsBuildInfoFile": "./tsconfig.tsbuildinfo"
    },
    "references": [{ "path": "../typescript-common" }],
    "include": ["./src"]
}
  1. tsconfig-web.json (extends the TS config file above):
{
    "extends": "./tsconfig.json",
    "compilerOptions": {
        "lib": [
            "dom",
            "es5",
            "scripthost",
            "es2015.core",
            "es2015.promise",
            "es2017"
        ]
    }
}
  1. Webpack config (use tsconfig-web.json to build TS code):
const path = require("path");
const webpack = require("webpack");
const TsconfigPathsPlugin = require("tsconfig-paths-webpack-plugin");

const configFile = path.resolve(__dirname, "../tsconfig-web.json");

module.exports = {
    entry: "./src/createTransformer.ts",
    mode: "production",
    output: {
        filename: "createTransformerForBrowser.js",
        path: path.join(__dirname, "..", "dist"),
        library: "createTransformer"
    },
    devtool: "source-map",
    module: {
        rules: [
            {
                test: /\.tsx?$/,
                exclude: /node_modules/,
                loader: "ts-loader",
                options: {
                    configFile,
                    projectReferences: true
                }
            }
        ]
    },
    resolve: {
        plugins: [
            new TsconfigPathsPlugin({
                configFile
            })
        ],
        extensions: [".tsx", ".ts", ".js"]
    },
    node: {
        fs: "empty"
    }
};
Actual Behaviour

Project reference doesn't work. And you will find the following errors:

ERROR in xx/xx.ts
[tsl] ERROR in /xx/typescript-common/src/xxxxxx.ts(9,30)
      TS6059: File '/xx/typescript-common/src/xx/xx.ts' is not under 'rootDir' '/xx'. 'rootDir' is expected to contain all source files.
Expected Behaviour

Should build without error.

However, if you either:

  • add "references": [{ "path": "../typescript-common" }], to tsconfig-web.json
  • Or modify webpack.config.js to use tsconfig.json to build (instead of tsconfig-web.json)

the build will complete with no error.

Steps to Reproduce the Problem

See: https://github.com/t83714/sample-repo-ts-loader

Location of a Minimal Repository that Demonstrates the Issue.

https://github.com/t83714/sample-repo-ts-loader

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked sample-repo-ts-loader repository and reproduce the failure using webpack.config.js with tsconfig-web.json. Compare that build with the working configurations described in the issue, then trace how ts-loader handles project references inherited through the tsconfig extends chain. Done means the sample build completes without the TS6059 rootDir error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript, webpack
Domain
build-system
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.