SonarCloudAnalyze@1 typescript references resolution is incorrect

Template for a good bug report, formatted with Markdown:

  • versions used (SonarQube, Scanner, Plugin, and any relevant extension)
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.25.0
  • error observed (wrap logs/code around triple quote ``` for proper formatting)
    tsconfig.json
{
  "files": [],
  "references": [
    {
      "path": "teams/acquisition"
    },
    {
      "path": "teams/checkout"
    },
    {
      "path": "teams/growth"
    },
    {
      "path": "teams/order-management"
    },
    {
      "path": "teams/presentation"
    },
    {
      "path": "teams/selling-tools"
    },
    {
      "path": "packages/codemod"
    },
    {
      "path": "packages/codemod/tests"
    },
    {
      "path": "packages/components"
    },
    {
      "path": "packages/components/tests"
    },
    {
      "path": "packages/css-variables"
    },
    {
      "path": "packages/css-variables/tests"
    },
    {
      "path": "packages/data-grid"
    },
    {
      "path": "packages/data-grid/tests"
    },
    {
      "path": "packages/fonts"
    },
    {
      "path": "packages/icons"
    },
    {
      "path": "packages/icons/tests"
    },
    {
      "path": "packages/internals"
    },
    {
      "path": "packages/license"
    },
    {
      "path": "packages/license/tests"
    },
    {
      "path": "packages/mui"
    },
    {
      "path": "packages/mui/tests"
    },
    {
      "path": "packages/test-utils"
    }
  ],
  "extends": "./tsconfig.options.json"
}

Error from ci

...
10:30:29.650 DEBUG: Adding referenced project's tsconfigs [/home/vsts/work/1/s/packages/mui]
##[error]10:30:29.652 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/packages/icons (Cannot read file '/home/vsts/work/1/s/packages/icons'.)
##[debug]Processed: ##vso[task.logissue type=error;]10:30:29.652 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/packages/icons (Cannot read file '/home/vsts/work/1/s/packages/icons'.)
10:30:29.652 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/packages/icons (Cannot read file '/home/vsts/work/1/s/packages/icons'.)
##[error]10:30:29.654 ERROR: Cannot read file '/home/vsts/work/1/s/packages/icons'.
##[debug]Processed: ##vso[task.logissue type=error;]10:30:29.654 ERROR: Cannot read file '/home/vsts/work/1/s/packages/icons'.
10:30:29.654 ERROR: Cannot read file '/home/vsts/work/1/s/packages/icons'.
##[error]10:30:29.657 ERROR: Cannot read file '/home/vsts/work/1/s/teams/acquisition'.
10:30:29.658 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/teams/acquisition (Cannot read file '/home/vsts/work/1/s/teams/acquisition'.)
##[debug]Processed: ##vso[task.logissue type=error;]10:30:29.657 ERROR: Cannot read file '/home/vsts/work/1/s/teams/acquisition'.%0A10:30:29.658 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/teams/acquisition (Cannot read file '/home/vsts/work/1/s/teams/acquisition'.)
10:30:29.657 ERROR: Cannot read file '/home/vsts/work/1/s/teams/acquisition'.
10:30:29.658 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/teams/acquisition (Cannot read file '/home/vsts/work/1/s/teams/acquisition'.)
##[error]10:30:29.659 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/teams/checkout (Cannot read file '/home/vsts/work/1/s/teams/checkout'.)
##[debug]Processed: ##vso[task.logissue type=error;]10:30:29.659 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/teams/checkout (Cannot read file '/home/vsts/work/1/s/teams/checkout'.)
10:30:29.659 ERROR: Failed to parse tsconfig: /home/vsts/work/1/s/teams/checkout (Cannot read file '/home/vsts/work/1/s/teams/checkout'.)
...
  • steps to reproduce
    • Monorepo with typescript
    • Reference only folders not tsconfig in main tsconfig.json
    • try to run SonarCloudAnalyze@1 in azure pipelines
  • potential workaround
    • Add tsconfig.json to references

I am trying to use SonarCloudAnalyze on our monorepo, we have existing working monorepo that have references by folder. Sonarcloud fails after trying to read folder as tsconfig.json

Hello @rajzik
and welcome to the SonarSource community!

Thanks for this detailed report, the limitation you’ve described seems only loosely related to mono-repositories, and is described with issue #2815: Support directories in references in tsconfig
I’ve linked back this SonarJS issue to your thread.

Best regards
Sylvain

1 Like