SonarCloud error in Azure build pipeline for blazer project Error: Cannot find module 'typescript'

  • ALM used Azure DevOps
  • CI system used Azure DevOps
  • Scanner command:
- task: SonarCloudPrepare@1
  displayName: 'Prepare SonarCloud analysis'
  inputs:
    SonarCloud: 'Connection'
    organization: '$(organization)'
    projectKey: '$(projectKey)'
    projectName: '$(projectName)'
    projectVersion: '$(Build.BuildNumber)'
    extraProperties: |
      sonar.exclusions=**/obj/**,**/*.dll
      sonar.branch.name=$(Build.SourceBranchName)
      sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
      sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
  • Languages of the repository C# .net core Blazer project with web programing languages(HTML, CSS JavaScript)

  • Error observed:

==============================================================================
Task         : Run Code Analysis
Description  : Run scanner and upload the results to the SonarCloud server.
Version      : 1.6.3
Author       : sonarsource
Help         : This task is not needed for Maven and Gradle projects since the scanner should be run as part of the build.

[More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
==============================================================================
[command]d:\a\_tasks\SonarCloudPrepare_GUID\1.7.0\classic-sonar-scanner-msbuild\SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.6.2
Using the .NET Framework version of the Scanner for MSBuild
Post-processing started.

...
Calling the SonarQube Scanner...
INFO: Scanner configuration file: d:\a\_tasks\SonarCloudPrepare_Guid\1.7.0\classic-sonar-scanner-msbuild\sonar-scanner-3.3.0.1492\bin\..\conf\sonar-scanner.properties
INFO: Project root configuration file: d:\a\1\.sonarqube\out\sonar-project.properties
INFO: SonarQube Scanner 3.3.0.1492
INFO: Java 1.8.0_212 Azul Systems, Inc. (64-bit)
INFO: Windows Server 2019 10.0 amd64
INFO: User cache: C:\Users\VssAdministrator\.sonar\cache
INFO: SonarQube server 8.0.0
INFO: Default locale: "en_US", source code encoding: "windows-1252" (analysis is platform dependent)
...

INFO: ------------- Run sensors on module Hlc.Dax.Core.Web
INFO: Sensor SonarCSS Metrics [cssfamily]
INFO: Sensor SonarCSS Metrics [cssfamily] (done) | time=110ms
INFO: Sensor SonarCSS Rules [cssfamily]
INFO: Sensor SonarCSS Rules [cssfamily] (done) | time=3819ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor JavaXmlSensor [java]
INFO: Sensor JavaXmlSensor [java] (done) | time=0ms
INFO: Sensor HTML [web]
INFO: Sensor HTML [web] (done) | time=62ms
INFO: Sensor SonarTS [typescript]
INFO: No tsconfig.json file found for 1 file(s) (Run in debug mode to see all of them). They will be analyzed with a default configuration.
INFO: Analyzing 1 typescript file(s) with the following configuration file DEFAULT_TSCONFIG
##[error]ERROR: internal/modules/cjs/loader.js:638
ERROR: internal/modules/cjs/loader.js:638
##[error]ERROR:     throw err;
ERROR:     ^
ERROR: 
ERROR: Error: Cannot find module 'typescript'
ERROR:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
ERROR:     at Function.Module._load (internal/modules/cjs/loader.js:562:25)
ERROR:     at Module.require (internal/modules/cjs/loader.js:690:17)
ERROR:     throw err;
ERROR:     ^
ERROR: 
ERROR: Error: Cannot find module 'typescript'
ERROR:     at Function.Module._resolveFilename (internal/modules/cjs/loader.js:636:15)
ERROR:     at Function.Module._load (internal/modules/cjs/loader.js:562:25)
ERROR:     at Module.require (internal/modules/cjs/loader.js:690:17)
##[error]ERROR:     at require (internal/modules/cjs/helpers.js:25:18)
ERROR:     at require (internal/modules/cjs/helpers.js:25:18)
##[error]ERROR:     at Object.<anonymous> (d:\a\1\.sonarqube\out\.sonar\mod5\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)
ERROR:     at Object.<anonymous> (d:\a\1\.sonarqube\out\.sonar\mod5\sonarts-bundle\node_modules\tslint\lib\language\walker\blockScopeAwareRuleWalker.js:20:10)
##[error]ERROR:     at Module._compile (internal/modules/cjs/loader.js:776:30)
ERROR:     at Module._compile (internal/modules/cjs/loader.js:776:30)
##[error]ERROR:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
ERROR:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
##[error]ERROR:     at Module.load (internal/modules/cjs/loader.js:653:32)
ERROR:     at Module.load (internal/modules/cjs/loader.js:653:32)
##[error]ERROR:     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
ERROR:     at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
##[error]ERROR:     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
ERROR:     at Function.Module._load (internal/modules/cjs/loader.js:585:3)
##[error]ERROR: External process `node --max-old-space-size=2048 d:\a\1\.sonarqube\out\.sonar\mod5\sonarts-bundle\node_modules\tslint-sonarts\bin\tsrunner` returned an empty output. Run with -X for more information
ERROR: External process `node --max-old-space-size=2048 d:\a\1\.sonarqube\out\.sonar\mod5\sonarts-bundle\node_modules\tslint-sonarts\bin\tsrunner` returned an empty output. Run with -X for more information
INFO: Sensor SonarTS [typescript] (done) | time=689ms
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor SonarJS [javascript]
##[error]ERROR: Failed to find 'typescript' module. Please check, NODE_PATH contains location of global 'typescript' or install locally in your project
ERROR: Failed to find 'typescript' module. Please check, NODE_PATH contains location of global 'typescript' or install locally in your project
INFO: 2 source files to be analyzed
INFO: Sensor SonarJS [javascript] (done) | time=814ms
INFO: Sensor ESLint-based SonarJS [javascript]
INFO: 2/2 source files have been analyzed
INFO: 2 source files to be analyzed
INFO: Sensor ESLint-based SonarJS [javascript] (done) | time=4636ms
INFO: 2/2 source files have been analyzed

  • Potential workaround
    I tried to npm install typescript in the problem project per error-cannot-find-module-typescript’s recommendation with the following task but there was no change as a result.
- task: Bash@3
  displayName: 'NPM Install TypeScript'
  inputs:
    targetType: 'inline'
    script: |
      #Install TypeScript
      dir

      cd Hlc.Dax.Core.Web

      npm install -g typescript

      cd ..

Hi,

Which type of agent are you using ? Self-Hosed ? Or Managed ? In which OS ?

Thanks.

Mickaël

1 Like

I am using an Microsoft-hosted Azure agent. Hosted Windows 2019 with VS2019.

pool:
  vmImage: 'windows-2019'