"ERROR: Unable to parse file" for numerous valid typescript files

When running a scan of a typescript (v4.4) project, I get a number of parser errors. The error reads:

ERROR: Unable to parse file: file:///path/to/file/file.ts
ERROR: Parse error at line 2 column 11:

The contents of each file are all perfectly valid typescript though e.g.

export default class DOMUtils {
    public static windowExists(): boolean {      
        return typeof window !== 'undefined';
   }
}

I’ve tried running both sonar-scanner (v4.5.0.2216) and sonarqube community (v7.9.6) with the same result. my tsconfig is as per the below. In case it’s relevant, this is a React/Next.js project):

{
  "compilerOptions": {
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "allowJs": true,
    "skipLibCheck": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noEmit": true,
    "esModuleInterop": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "jsx": "preserve",
    "incremental": true,
    "baseUrl": ".",
    "paths": {
      "@components/*": ["components/*"],
      "@models/*": ["models/*"],
      "@pages/*": ["pages/*"],
      "@styles/*": ["styles/*"],
      "@tests/*": ["__tests__/*"],
      "@utils/*": ["utils/*"]
    },
    "typeRoots": ["./@types", "node_modules/@types"]
  },
  "include": ["**/*.ts", "**/*.tsx"],
  "exclude": ["node_modules"]
}

I’ve tried rolling project back as far as typescript v3.3 to see if it was related to that, which made no difference.

If anyone has any ideas on what the issue might be i’d be hugely greatful, sinking hours/days into this with no progress :frowning: from the range of parser errors it appears to be tripping up on typescript keywords

Hi,

Welcome to the community!

Your version is past EOL. You should upgrade to either the latest version or the current LTS at your earliest convenience. Your upgrade path is:

7.9.6 → 8.9.7 → 9.3 (last step optional)

You may find the Upgrade Guide and the LTS-to-LTS Upgrade Notes helpful. If you have questions about upgrading, feel free to open a new thread for that here.

If your error persists after upgrade, please come back to us.

 
HTH,
Ann

Hey Ann

Thanks for the response. I’ve tried running against a local instant of latest community release and it works fine. No for the less easy coversation to upgrade the SQ cluster for the organisation! he he

Thanks
James

1 Like