Installing the scanner
How to install the SonarScanner for NPM.
Depending on how you want to start the scanner, you will use a different installation method:
To start the scanner by adding the analysis to your build files: add the package to your project devDependencies.
To start the scanner from the command line: install the package in global mode.
To run analyses with npx: no installation is required.
Prerequisites
To analyze JavaScript, TypeScript, or CSS code, the SonarScanner for NPM requires that your Node.js must be at least 18.20.0.
See also the General requirements page for additional requirements.
Adding the scanner to your project devDependencies
Use the following command:
npm install -D @sonar/scanInstalling the scanner in global mode
Use the following command:
npm install -g @sonar/scanPerforming advanced setup
Changing the scanner cache folder
By default, the scanner binaries are cached into $HOME/.sonar/native-sonar-scanner folder. To use a custom cache folder instead of $HOME, set $SONAR_BINARY_CACHE.
Example:
export SONAR_BINARY_CACHE=/Users/myaccount/cacheor alternatively, set the variable in .npmrc:
sonar_binary_cache=/Users/myaccount/cache Setting up the connection to a proxy server
In case the CI/CD host is behind a proxy, you must define the proxy-related analysis parameters required to connect to your proxy server to allow the scanner to download the scanner binaries. For more information, see Analysis parameters. You may also use the HTTP_PROXY or HTTPS_PROXY environment variable.
Examples:
sonar.scanner.proxyHost=mycompanyproxy.comsonar.scanner.proxyPort=4254sonar.scanner.proxyUser=syssonar.scanner.proxyPassword=e12iUp!HTTP_PROXY=http://user:[email protected]:PORT
If your instance of SonarQube Community Build is secured
If your SonarQube Community Build instance is secured behind a proxy and a self-signed certificate then you must add the self-signed certificate to the trusted CA certificates of the SonarScanner. In addition, if mutual TLS is used then you must define the access to the client certificate at the SonarScanner level.
See TLS certificates on client side.
Troubleshooting the installation
Docker container: the scanner fails with "…/jre/bin/java: not found"
You are probably relying on Alpine for your Docker image, and Alpine does not include glibc by default. It needs to be installed manually.
Last updated
Was this helpful?

