Setting Node Executable for Typescript Analysis

Hi All,

I’m getting below errors and I tried add the property below one but no luck. could anyone please help how to fix this?

sonar.typescript.node=C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Microsoft\VisualStudio\NodeJs\node.exe

*****************************************************************************
 ERROR: Failed to get Node.js version.No TypeScript files will be analyzed. You can exclude TypeScript files from analysis with 'sonar.exclusions' property.
 java.io.IOException: Cannot run program "node": CreateProcess error=2, The system cannot find the file specified
 	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
 	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
 	at java.base/java.lang.Runtime.exec(Runtime.java:592)
 	at java.base/java.lang.Runtime.exec(Runtime.java:416)
 	at java.base/java.lang.Runtime.exec(Runtime.java:313)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.checkCompatibleNodeVersion(ExternalTypescriptSensor.java:158)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.analyze(ExternalTypescriptSensor.java:117)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.execute(ExternalTypescriptSensor.java:111)
 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
 	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
 	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
 	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
 	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
 Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
 	at java.base/java.lang.ProcessImpl.create(Native Method)
 	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:478)
 	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154)
 	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
 	... 37 common frames omitted
 
 INFO: ------------------------------------------------------------------------
 INFO: EXECUTION FAILURE
 INFO: ------------------------------------------------------------------------
 INFO: Total time: 16.941s
 INFO: Final Memory: 29M/104M
 INFO: ------------------------------------------------------------------------
 ERROR: Error during SonarScanner execution
 java.lang.IllegalStateException: Failed to get Node.js version.No TypeScript files will be analyzed. You can exclude TypeScript files from analysis with 'sonar.exclusions' property.
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.checkCompatibleNodeVersion(ExternalTypescriptSensor.java:163)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.analyze(ExternalTypescriptSensor.java:117)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.execute(ExternalTypescriptSensor.java:111)
 	at org.sonar.scanner.sensor.AbstractSensorWrapper.analyse(AbstractSensorWrapper.java:48)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:85)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.lambda$execute$1(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.withModuleStrategy(ModuleSensorsExecutor.java:77)
 	at org.sonar.scanner.sensor.ModuleSensorsExecutor.execute(ModuleSensorsExecutor.java:59)
 	at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:82)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:386)
 	at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:382)
 	at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:351)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.scanner.bootstrap.GlobalContainer.doAfterStart(GlobalContainer.java:141)
 	at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
 	at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
 	at org.sonar.batch.bootstrapper.Batch.doExecute(Batch.java:72)
 	at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:66)
 	at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
 	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
 	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
 	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
 	at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
 	at com.sun.proxy.$Proxy0.execute(Unknown Source)
 	at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:189)
 	at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:138)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:112)
 	at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
 	at org.sonarsource.scanner.cli.Main.main(Main.java:61)
 Caused by: java.io.IOException: Cannot run program "node": CreateProcess error=2, The system cannot find the file specified
 	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1128)
 	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1071)
 	at java.base/java.lang.Runtime.exec(Runtime.java:592)
 	at java.base/java.lang.Runtime.exec(Runtime.java:416)
 	at java.base/java.lang.Runtime.exec(Runtime.java:313)
 	at org.sonar.plugin.typescript.ExternalTypescriptSensor.checkCompatibleNodeVersion(ExternalTypescriptSensor.java:158)
 	... 32 more
 Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
 	at java.base/java.lang.ProcessImpl.create(Native Method)
 	at java.base/java.lang.ProcessImpl.<init>(ProcessImpl.java:478)
 	at java.base/java.lang.ProcessImpl.start(ProcessImpl.java:154)
 	at java.base/java.lang.ProcessBuilder.start(ProcessBuilder.java:1107)
 	... 37 more
 ERROR: 
 ERROR: Re-run SonarScanner using the -X switch to enable full debug logging.
 WARN: Unable to locate 'report-task.txt' in the workspace. Did the SonarScanner succeeded?
 ERROR: SonarQube scanner exited with non-zero code: 1

Hi there.

What version of SonarQube are you using, and what version of the Typescript analyzer?

Hi @Colin_SonarSource

currently we are 8.2 sonarqube enterprise version and how to check the Typescript analyzer?

That answers enough (although for future reference, try the global Administration > Marketplace), or most log outputs from the scanner).

Try using sonar.nodejs.executable rather than sonar.typescript.node as documented in the Typescript Analysis Docs.

Prerequisites

In order to analyze TypeScript code, you need to have Node.js >= 8 installed on the machine running the scan. If standard node is not available, you have to set property sonar.nodejs.executable to an absolute path to Node.js executable.

Also make sure to have TypeScript as a project dependency or dev dependency. If it’s not the case, add it:

cd <your-project-folder>
npm install -D typescript

If you can’t have TypeScript as a project dependency you can set your NODE_PATH variable to point to your globally installed TypeScript (but this is generally discouraged by the Node.js documentation).

Tried sonar.nodejs.executable and no luck. still failing

@Colin_SonarSource @ganncamp @NicoB

can I know how to add the type script to sonar.exclusions property.?

-Dsonar.exclusions=**/*.ts

1 Like

I have the same issue with sonar.nodejs.executable not working as documented. In our Java/TypeScript project, SonarQube is invoked via SonarScanner for Gradle v3.0. We’re using SonarQube Community LTS Version 7.9.1. When Node.js in on the PATH, everything works. However, Node.js is configured to be downloaded to the project dir by Gradle and everything went haywire since TypeScript analysis was enabled.

I’ve tried to use:

  1. build.gradle:
sonarqube {
    properties {
        //region TypeScript analysis
        property "sonar.nodejs.executable", '{absolute project path}/.gradle/nodejs/node-v12.18.1-darwin-x64/bin/node'
        //endregion
    }
}

or

  1. ./gradlew -Dsonar.nodejs.executable={absolute project path}/.gradle/nodejs/node-v12.18.1-darwin-x64/bin/node clean sonarqube

These fail on Mac or Linux.

What gives?

I’m going to give up on sonar.nodejs.executable for now and set system PATH for Gradle, but it’s less than ideal.