Sonar-scanner (TypeScript): Cannot read property 'map' of undefined

SonarQube 7.9.2.30863
SonarQube Scanner 3.3.0.1492
Java 1.8.0_252 Oracle Corporation (64-bit)
Linux 4.19.123-coreos amd64
SonarJS 6.2.1

When running sonar-scanner, I’m seeing lots of these kinds of errors (names redacted):

ERROR: Failed to analyze file [scripts/.../foo.ts]: Cannot read property 'map' of undefined
ERROR: Failed to analyze file [scripts/.../foo.ts]: Cannot read property 'map' of undefined
ERROR: Failed to analyze file [scripts/.../foo.ts]: Cannot read property 'map' of undefined
INFO: 57/1447 files analyzed, current file: scripts/.../foo.ts
ERROR: Failed to analyze file [src/.../foo.ts]: Cannot read property 'map' of undefined
ERROR: Failed to analyze file [src/.../foo.ts]: Cannot read property 'map' of undefined
ERROR: Failed to analyze file [src/.../foo.ts]: Cannot read property 'map' of undefined
INFO: 281/1447 files analyzed, current file: src/.../foo.ts
ERROR: Failed to analyze file [src/.../foo.ts]: Cannot read property 'map' of undefined
ERROR: Failed to analyze file [src/.../foo.ts]: Cannot read property 'map' of undefined
ERROR: Failed to analyze file [src/.../foo.ts]: Cannot read property 'map' of undefined

I’m seeing this for about 50 files in our repo. All of them are TypeScript. I’m not exactly sure what more information you need to debug this, so please let me know.

Bump. Seems like a pretty obvious bug in the scanner.

I have the same issue after upgrading my angular project to version. My project uses typescript 4.0.2 now.
SonarScanner 4.4.0.2170
Java 1.8.0_202

Yeah, we’re also using the latest version of TypeScript. Seems like SonarJS doesn’t support it?

It doesnt. Logs state
You are using version of TypeScript 4.0.2 which is not officially supported; supported versions >=3.2.1 <3.8.0
Were you able to figure out a workaround?

No, I guess we’ll just have to wait for updates. I’ve run into issues with other tools (e.g. @typescript-eslint) that don’t support TypeScript 4 either.

Hello @kaiyoma and welcome to our community,

First of all, sorry for the late answer as I see this thread has been open for quite some time now.

Indeed SonarJS doesn’t support TypeScript 4 at the moment (we plan to add support in the following months though). In the meantime, the impact you should expect is simply not to have any analysis performed on files using TypeScript 4 features.

That said, just so we’re sure that this is the root cause of the issue you’re facing, can you confirm that you only have this problem on files that are using TypeScript 4 features? Could you maybe please provide me with a small reproducer file that triggers this issue (maybe in a private message) ?

Thank you,
Guillaume

1 Like

Hi @Guillaume_Dequenne,

How can we track the TypeScript 4 progress? The current Angular version ships with TypeScript 4.

Hello @Ferdie,

TypeScript 4(.1) is supported since SonarJS 7.2, which is available on SonarCloud and SonarQube 8.7.

Hope this helps,
Yassin

1 Like

I think the base of this incompatibility cames from the use of typescript tuples in types definitions.

In my case i have this error only in files that contains something like this:

type MinMaxRange = [number, number];

For me, it’s also happening in files having Typescript enums, like:

enum TravelDirectionEnum {
  INBOUND = 1,
  OUTBOUND = 2,
}

Hello @dardino,
Hello @colinD,

Thank you for your feedbacks, and welcome to the SonarSource community !

I was not able to reproduce this undefined error using the two code snippets you shared. Since this thread was created a while ago (at the time of a different SonarQube version) and was inactive until very recently, I am going to close it.

In the meantime, I invite you to create another thread to report a bug, this time sharing which SonarQube version you are using as well as a project configuration along with a minimal, reproducible example that I could use to faithfully reproduce the issue you are encountering.

Thank you,
Yassin