tsc fails with TypeError when I specify rootDirs:null with composite:true in an extended tsconfig
#43,061 opened on Mar 3, 2021
Description
Bug Report
🔎 Search Terms
tsconfig extend rootDirs with null Cannot read property length of undefined composite
🕗 Version & Regression Information
I encountered it at typescript@4.1.3 and also reproduced in the latest v4.2.2
From https://github.com/microsoft/TypeScript/pull/18058 I assume overriding extended fields that you want to unset should be possible with null.
And it does apparently work ok unles you specify "composite": true.
- This is the behavior in every version I tried, and I reviewed the FAQ for entries about tsconfig.json Behavior (no mentions of "extend", "rootDirs", "composite" there)
⏯ Playground Link
It's about tsconfig, not about language itself, don't see an option to modify tsconfig in the playground, so here is a minimal reproduction repo:
https://github.com/klesun-productions/tsconfig-src-roots-null-bug-example
💻 Code
tsconfig-base.json
{
"compilerOptions": {
"rootDirs": ["src", "test"]
}
}
tsconfig.json
{
"extends": "./tsconfig-base.json",
"compilerOptions": {
"composite": true,
"rootDirs": null,
"rootDir": "src"
}
}
🙁 Actual behavior
npm run tsc in the demo project results in following stack trace:
klesun@kunkka:~/gits/tsconfig-src-roots-null-bug-example$ npm run tsc
> tsconfig-src-roots-null-bug-example@1.0.0 tsc /home/klesun/gits/tsconfig-src-roots-null-bug-example
> tsc
/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90526
if (option.element.isFilePath && values.length) {
^
TypeError: Cannot read property 'length' of undefined
at convertToReusableCompilerOptionValue (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90526:57)
at convertToReusableCompilerOptions (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90514:32)
at getProgramBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90452:22)
at Object.newProgram.getProgramBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:90606:63)
at Object.getProgramBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:87903:98)
at emitBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:82111:32)
at emitSourceFileOrBundle (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:82083:13)
at forEachEmittedFile (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:81828:28)
at Object.emitFiles (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:82057:9)
at Object.emitBuildInfo (/home/klesun/gits/tsconfig-src-roots-null-bug-example/node_modules/typescript/lib/tsc.js:87913:33)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! tsconfig-src-roots-null-bug-example@1.0.0 tsc: `tsc`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the tsconfig-src-roots-null-bug-example@1.0.0 tsc script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
npm ERR! A complete log of this run can be found in:
npm ERR! /home/klesun/.npm/_logs/2021-03-03T15_12_47_873Z-debug.log
🙂 Expected behavior
Either validation of tsconfig fields should yield a meaningful error (like it does if you specify 123 as rootDirs value for example error TS5024: Compiler option 'rootDirs' requires a value of type Array.), or it should work like described in https://github.com/microsoft/TypeScript/pull/18058 - treat null as removal of this field from the inherited config object.
Currently using "rootDirs": [] workaround seems to be an equivalent of this field to be not set.
Blind guess, but could it be that somewhere in the tsc implementation you are assuming that if config object has the key then this key can't be undefined?