TypeStrong / TypeStrong/ts-loader
Project References won't work if extends config file
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:
- tsconfig.json:
{
"extends": "../tsconfig-global.json",
"compilerOptions": {
"outDir": "./dist",
"strictNullChecks": false,
"rootDir": "./src",
"tsBuildInfoFile": "./tsconfig.tsbuildinfo"
},
"references": [{ "path": "../typescript-common" }],
"include": ["./src"]
}
- tsconfig-web.json (extends the TS config file above):
{
"extends": "./tsconfig.json",
"compilerOptions": {
"lib": [
"dom",
"es5",
"scripthost",
"es2015.core",
"es2015.promise",
"es2017"
]
}
}
- Webpack config (use
tsconfig-web.jsonto 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" }],totsconfig-web.json - Or modify
webpack.config.jsto usetsconfig.jsonto build (instead oftsconfig-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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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