Failed build under TypeScript 4.5.2
fluggo opened this issue · comments
Under TypeScript 4.5.2, my tests fail to start with errors like:
21 11 2021 13:35:13.188:ERROR [karma-server]: Error: Unable to resolve module [set] from [/dir/packages/graphlib/lib/graph.spec.js]
21 11 2021 13:35:13.190:ERROR [karma-server]: Error: Unable to resolve module [get] from [/dir/packages/graphlib/lib/graph.spec.js]
21 11 2021 13:35:13.190:ERROR [karma-server]: Error: Unable to resolve module [delete] from [/dir/packages/graphlib/lib/graph.spec.js]
The crux of this problem appears to happen at this line of compiler.ts:
const sourceFile = this.program.getSourceFile(queued.file.originalPath);
Under TypeScript 4.4.4, the resolvedModules
property of sourceFile is a true ES6 Map, as far as I can tell.
Under TypeScript 4.5.2, that property has changed to the Map-like ModeAwareCache, which apparently isn't enough like a Map to satisfy whatever comes after this line.
Reverting to TypeScript 4.4 is a workaround.
Yes, we have this problem as well, see issue linked above.
Solution is to implement better Map check on line if (lodash.isMap(resolvedModules)) { // Typescript 2.2+
for new ModeAwareCache lodash.isMap
is evaluated as false and it will go into else
branch which is wrong
Some easy fix is to create primitive ModeAwareCache
check function like
var isTS45Map = function(map){
return typeof map.get === "function" &&
typeof map.set === "function" &&
typeof map.delete === "function" &&
typeof map.has === "function" &&
typeof map.forEach === "function" &&
typeof map.size === "function";
}
and use it on the line like
if (isTS45Map(resolvedModules) || lodash.isMap(resolvedModules)) { // Typescript 2.2+
I created my own scoped package with fix https://www.npmjs.com/package/@sedlak.r/karma-typescript/v/5.5.2-issue499fix.2
If you are familiar with lockfile, you can change karma-typescript lockfile entry somehow like this for Yarn:
karma-typescript@^5.5.2:
version "5.5.2"
resolved "https://registry.yarnpkg.com/@sedlak.r/karma-typescript/-/karma-typescript-5.5.2-issue499fix.2.tgz#44300c12aff4b618f770d5530c7e2764ab0e5158"
integrity sha512-wmcetaplK95YK7Rd3Yyv9BFRJImSe+V/yAaGqDCoQlbP+xYwHWW7yUdCNFn3Wkn+y0YwWESYMU1X4ozzKf/z7w==