I have multiple installations of Node.js, depending on the version I need for my projects, and I've noticed that I can't run the command 'sonar-scanner' while I'm using Node 22.9.0.
I've installed the tool with npm install -g sonarqube-scanner
, and I'm launching it using sonar-scanner
from within the root of my Angular project. When I use Node 18.16.0 the SonarQube analysis runs normally:
[10:19:44] Starting analysis...
[10:19:45] Executable parameters built:
[10:19:45] {
httpOptions: {},
targetOS: 'windows',
installFolder: 'C:\\Users\\eeml\\.sonar\\native-sonar-scanner',
platformExecutable: 'C:\\Users\\eeml\\.sonar\\native-sonar-scanner\\sonar-scanner-5.0.1.3006-windows\\bin\\sonar-scanner.bat',
fileName: 'sonar-scanner-cli-5.0.1.3006-windows.zip',
downloadUrl: 'https://binaries.sonarsource.com/Distribution/sonar-scanner-cli/sonar-scanner-cli-5.0.1.3006-windows.zip'
}
[10:19:45] Trying to find a local install of the SonarScanner: C:\Users\eeml\.sonar\native-sonar-scanner\sonar-scanner-5.0.1.3006-windows\bin\sonar-scanner.bat
...
...
...
But when I use Node 22.9.0, the only output I get is:
[INFO] Bootstrapper: Retrieving info from "package.json" file
[INFO] Bootstrapper: Platform: win32 x64
[INFO] Bootstrapper: Server URL: https://sonarcloud.io
[INFO] Bootstrapper: Version: 4.2.5
[INFO] Bootstrapper: JRE provisioning is supported
[ERROR] Bootstrapper: An error occurred: AxiosError: Request failed with status code 401
Am I missing any dependency or something like that? I don't recognize the term "AxiosError" and don't know where to start. I installed the sonar-scanner tool using the same command, I change Node.js versions using nvm, and I'm testing it in the same project.
Solved, apparently on new versions I can't use the command sonar-scanner
and rely on the properties file, so the analysis has to be done with the full command:
sonar-scanner -Dsonar.projectKey="<name of your project>" -Dsonar.host.url=<your url> -Dsonar.token=<your token>
.